@lssm/lib.contracts 0.0.0-canary-20251217062943 → 0.0.0-canary-20251217072406

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/dist/app-config/app-config.feature.js +53 -1
  2. package/dist/app-config/contracts.d.ts +50 -50
  3. package/dist/app-config/contracts.js +396 -1
  4. package/dist/app-config/docs/app-config.docblock.js +22 -220
  5. package/dist/app-config/events.js +168 -1
  6. package/dist/app-config/index.js +8 -1
  7. package/dist/app-config/lifecycle-contracts.js +441 -1
  8. package/dist/app-config/runtime.js +617 -1
  9. package/dist/app-config/spec.js +36 -1
  10. package/dist/app-config/validation.js +538 -1
  11. package/dist/capabilities/docs/capabilities.docblock.js +22 -1
  12. package/dist/capabilities/openbanking.js +92 -1
  13. package/dist/capabilities.js +50 -1
  14. package/dist/client/index.js +9 -1
  15. package/dist/client/react/drivers/rn-reusables.js +21 -1
  16. package/dist/client/react/drivers/shadcn.js +11 -1
  17. package/dist/client/react/feature-render.js +43 -1
  18. package/dist/client/react/form-render.js +298 -1
  19. package/dist/client/react/index.js +8 -1
  20. package/dist/contract-registry/index.js +3 -1
  21. package/dist/contract-registry/schemas.js +61 -1
  22. package/dist/contracts-adapter-hydration.js +41 -1
  23. package/dist/contracts-adapter-input.js +77 -1
  24. package/dist/data-views/docs/data-views.docblock.js +22 -1
  25. package/dist/data-views/query-generator.js +48 -1
  26. package/dist/data-views/runtime.js +39 -1
  27. package/dist/data-views.js +35 -1
  28. package/dist/docs/PUBLISHING.docblock.js +17 -76
  29. package/dist/docs/accessibility_wcag_compliance_specs.docblock.js +17 -350
  30. package/dist/docs/index.js +33 -1
  31. package/dist/docs/meta.docs.js +15 -2
  32. package/dist/docs/presentations.js +77 -1
  33. package/dist/docs/registry.js +51 -1
  34. package/dist/docs/tech/PHASE_1_QUICKSTART.docblock.js +17 -383
  35. package/dist/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS.docblock.js +17 -68
  36. package/dist/docs/tech/PHASE_3_AUTO_EVOLUTION.docblock.js +17 -140
  37. package/dist/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js +17 -86
  38. package/dist/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js +17 -1
  39. package/dist/docs/tech/auth/better-auth-nextjs.docblock.js +25 -2
  40. package/dist/docs/tech/contracts/README.docblock.js +21 -1
  41. package/dist/docs/tech/contracts/create-subscription.docblock.js +21 -1
  42. package/dist/docs/tech/contracts/graphql-typed-outputs.docblock.js +21 -180
  43. package/dist/docs/tech/contracts/migrations.docblock.js +21 -1
  44. package/dist/docs/tech/contracts/openapi-export.docblock.js +22 -2
  45. package/dist/docs/tech/contracts/ops-to-presentation-linking.docblock.js +19 -60
  46. package/dist/docs/tech/contracts/overlays.docblock.js +21 -68
  47. package/dist/docs/tech/contracts/tests.docblock.js +21 -132
  48. package/dist/docs/tech/contracts/themes.docblock.js +21 -1
  49. package/dist/docs/tech/contracts/vertical-pocket-family-office.docblock.js +21 -106
  50. package/dist/docs/tech/lifecycle-stage-system.docblock.js +17 -213
  51. package/dist/docs/tech/llm/llm-integration.docblock.js +74 -5
  52. package/dist/docs/tech/mcp-endpoints.docblock.js +38 -1
  53. package/dist/docs/tech/presentation-runtime.docblock.js +17 -1
  54. package/dist/docs/tech/schema/README.docblock.js +21 -262
  55. package/dist/docs/tech/studio/learning-events.docblock.js +49 -1
  56. package/dist/docs/tech/studio/learning-journeys.docblock.js +25 -2
  57. package/dist/docs/tech/studio/platform-admin-panel.docblock.js +24 -2
  58. package/dist/docs/tech/studio/project-access-teams.docblock.js +26 -16
  59. package/dist/docs/tech/studio/project-routing.docblock.js +68 -1
  60. package/dist/docs/tech/studio/sandbox-unlogged.docblock.js +23 -2
  61. package/dist/docs/tech/studio/team-invitations.docblock.js +41 -36
  62. package/dist/docs/tech/studio/workspace-ops.docblock.js +48 -1
  63. package/dist/docs/tech/studio/workspaces.docblock.js +24 -2
  64. package/dist/docs/tech/telemetry-ingest.docblock.js +37 -3
  65. package/dist/docs/tech/templates/runtime.docblock.js +21 -1
  66. package/dist/docs/tech/vscode-extension.docblock.js +37 -3
  67. package/dist/docs/tech/workflows/overview.docblock.js +21 -1
  68. package/dist/docs/tech-contracts.docs.js +19 -2
  69. package/dist/events.js +12 -1
  70. package/dist/experiments/docs/experiments.docblock.js +22 -128
  71. package/dist/experiments/evaluator.js +101 -1
  72. package/dist/experiments/spec.js +33 -1
  73. package/dist/features.js +68 -1
  74. package/dist/forms/docs/forms.docblock.js +22 -1
  75. package/dist/forms.js +119 -1
  76. package/dist/index.js +107 -1
  77. package/dist/install.js +40 -1
  78. package/dist/integrations/contracts.d.ts +102 -102
  79. package/dist/integrations/contracts.js +388 -1
  80. package/dist/integrations/docs/integrations.docblock.js +95 -1
  81. package/dist/integrations/health.js +69 -1
  82. package/dist/integrations/index.js +23 -1
  83. package/dist/integrations/openbanking/contracts/accounts.d.ts +66 -66
  84. package/dist/integrations/openbanking/contracts/accounts.js +237 -1
  85. package/dist/integrations/openbanking/contracts/balances.d.ts +34 -34
  86. package/dist/integrations/openbanking/contracts/balances.js +167 -1
  87. package/dist/integrations/openbanking/contracts/index.js +12 -1
  88. package/dist/integrations/openbanking/contracts/transactions.d.ts +48 -48
  89. package/dist/integrations/openbanking/contracts/transactions.js +218 -1
  90. package/dist/integrations/openbanking/guards.js +32 -1
  91. package/dist/integrations/openbanking/models.d.ts +55 -55
  92. package/dist/integrations/openbanking/models.js +242 -1
  93. package/dist/integrations/openbanking/openbanking.feature.js +68 -1
  94. package/dist/integrations/openbanking/telemetry.js +39 -1
  95. package/dist/integrations/providers/elevenlabs.js +56 -1
  96. package/dist/integrations/providers/gcs-storage.js +79 -1
  97. package/dist/integrations/providers/gmail.js +91 -1
  98. package/dist/integrations/providers/google-calendar.js +70 -1
  99. package/dist/integrations/providers/impls/elevenlabs-voice.js +95 -1
  100. package/dist/integrations/providers/impls/gcs-storage.js +88 -1
  101. package/dist/integrations/providers/impls/gmail-inbound.js +200 -1
  102. package/dist/integrations/providers/impls/gmail-outbound.js +104 -5
  103. package/dist/integrations/providers/impls/google-calendar.js +154 -1
  104. package/dist/integrations/providers/impls/index.js +16 -1
  105. package/dist/integrations/providers/impls/mistral-embedding.js +41 -1
  106. package/dist/integrations/providers/impls/mistral-llm.js +247 -1
  107. package/dist/integrations/providers/impls/postmark-email.js +55 -1
  108. package/dist/integrations/providers/impls/powens-client.js +171 -1
  109. package/dist/integrations/providers/impls/powens-openbanking.js +218 -1
  110. package/dist/integrations/providers/impls/provider-factory.js +142 -1
  111. package/dist/integrations/providers/impls/qdrant-vector.js +69 -1
  112. package/dist/integrations/providers/impls/stripe-payments.js +202 -1
  113. package/dist/integrations/providers/impls/twilio-sms.js +58 -1
  114. package/dist/integrations/providers/index.js +13 -1
  115. package/dist/integrations/providers/mistral.js +72 -1
  116. package/dist/integrations/providers/postmark.js +72 -1
  117. package/dist/integrations/providers/powens.js +120 -1
  118. package/dist/integrations/providers/qdrant.js +77 -1
  119. package/dist/integrations/providers/registry.js +34 -1
  120. package/dist/integrations/providers/stripe.js +87 -1
  121. package/dist/integrations/providers/twilio-sms.js +65 -1
  122. package/dist/integrations/runtime.js +186 -1
  123. package/dist/integrations/secrets/aws-secret-manager.js +231 -1
  124. package/dist/integrations/secrets/env-secret-provider.js +81 -1
  125. package/dist/integrations/secrets/gcp-secret-manager.js +229 -1
  126. package/dist/integrations/secrets/index.js +8 -1
  127. package/dist/integrations/secrets/manager.js +103 -1
  128. package/dist/integrations/secrets/provider.js +58 -1
  129. package/dist/integrations/secrets/scaleway-secret-manager.js +247 -1
  130. package/dist/integrations/spec.js +39 -1
  131. package/dist/jobs/define-job.js +16 -1
  132. package/dist/jobs/gcp-cloud-tasks.js +53 -1
  133. package/dist/jobs/gcp-pubsub.js +39 -1
  134. package/dist/jobs/handlers/gmail-sync-handler.js +9 -1
  135. package/dist/jobs/handlers/index.js +12 -1
  136. package/dist/jobs/handlers/ping-handler.js +15 -1
  137. package/dist/jobs/handlers/storage-document-handler.js +14 -1
  138. package/dist/jobs/index.js +4 -1
  139. package/dist/jobs/memory-queue.js +71 -1
  140. package/dist/jobs/queue.js +33 -1
  141. package/dist/jobs/scaleway-sqs-queue.js +153 -1
  142. package/dist/jsonschema.d.ts +3 -3
  143. package/dist/jsonschema.js +32 -1
  144. package/dist/knowledge/contracts.d.ts +66 -66
  145. package/dist/knowledge/contracts.js +317 -1
  146. package/dist/knowledge/docs/knowledge.docblock.js +22 -138
  147. package/dist/knowledge/index.js +10 -1
  148. package/dist/knowledge/ingestion/document-processor.js +54 -1
  149. package/dist/knowledge/ingestion/embedding-service.js +25 -1
  150. package/dist/knowledge/ingestion/gmail-adapter.js +50 -5
  151. package/dist/knowledge/ingestion/index.js +7 -1
  152. package/dist/knowledge/ingestion/storage-adapter.js +26 -1
  153. package/dist/knowledge/ingestion/vector-indexer.js +32 -1
  154. package/dist/knowledge/query/index.js +3 -1
  155. package/dist/knowledge/query/service.js +64 -2
  156. package/dist/knowledge/runtime.js +49 -1
  157. package/dist/knowledge/spaces/email-threads.js +38 -1
  158. package/dist/knowledge/spaces/financial-docs.js +38 -1
  159. package/dist/knowledge/spaces/financial-overview.js +42 -1
  160. package/dist/knowledge/spaces/index.js +8 -1
  161. package/dist/knowledge/spaces/product-canon.js +38 -1
  162. package/dist/knowledge/spaces/support-faq.js +41 -1
  163. package/dist/knowledge/spaces/uploaded-docs.js +38 -1
  164. package/dist/knowledge/spec.js +39 -1
  165. package/dist/llm/exporters.js +541 -8
  166. package/dist/llm/index.js +4 -1
  167. package/dist/llm/prompts.js +246 -56
  168. package/dist/markdown.js +116 -3
  169. package/dist/migrations.js +33 -1
  170. package/dist/onboarding-base.d.ts +29 -29
  171. package/dist/onboarding-base.js +196 -1
  172. package/dist/openapi.js +75 -1
  173. package/dist/openbanking/docs/openbanking.docblock.js +22 -109
  174. package/dist/ownership.js +40 -1
  175. package/dist/policy/docs/policy.docblock.js +22 -1
  176. package/dist/policy/engine.js +223 -1
  177. package/dist/policy/opa-adapter.js +71 -1
  178. package/dist/policy/spec.js +33 -1
  179. package/dist/presentations/docs/presentations-conventions.docblock.js +21 -7
  180. package/dist/presentations.backcompat.js +47 -1
  181. package/dist/presentations.d.ts +3 -3
  182. package/dist/presentations.js +66 -1
  183. package/dist/presentations.v2.js +278 -6
  184. package/dist/prompt.js +10 -1
  185. package/dist/promptRegistry.js +34 -1
  186. package/dist/regenerator/docs/regenerator.docblock.js +22 -184
  187. package/dist/regenerator/executor.js +86 -1
  188. package/dist/regenerator/index.js +6 -1
  189. package/dist/regenerator/service.js +92 -1
  190. package/dist/regenerator/sinks.js +32 -1
  191. package/dist/regenerator/utils.js +51 -1
  192. package/dist/registry.js +208 -1
  193. package/dist/resources.js +47 -1
  194. package/dist/schema/dist/EnumType.js +2 -1
  195. package/dist/schema/dist/FieldType.js +49 -1
  196. package/dist/schema/dist/ScalarTypeEnum.js +236 -1
  197. package/dist/schema/dist/SchemaModel.js +39 -1
  198. package/dist/schema/dist/entity/defineEntity.js +1 -1
  199. package/dist/schema/dist/entity/index.js +2 -1
  200. package/dist/schema/dist/entity/types.js +1 -1
  201. package/dist/schema/dist/index.js +6 -1
  202. package/dist/schema-to-markdown.js +214 -10
  203. package/dist/server/graphql-pothos.js +128 -1
  204. package/dist/server/index.js +10 -1
  205. package/dist/server/mcp/createMcpServer.js +28 -1
  206. package/dist/server/mcp/registerPresentations.js +151 -1
  207. package/dist/server/mcp/registerPrompts.js +36 -2
  208. package/dist/server/mcp/registerResources.js +35 -1
  209. package/dist/server/mcp/registerTools.js +22 -1
  210. package/dist/server/provider-mcp.js +3 -1
  211. package/dist/server/rest-elysia.js +20 -1
  212. package/dist/server/rest-express.js +39 -1
  213. package/dist/server/rest-generic.js +125 -1
  214. package/dist/server/rest-next-app.js +38 -1
  215. package/dist/server/rest-next-mcp.js +45 -1
  216. package/dist/server/rest-next-pages.js +25 -1
  217. package/dist/spec.js +35 -1
  218. package/dist/telemetry/anomaly.js +48 -1
  219. package/dist/telemetry/docs/telemetry.docblock.js +22 -139
  220. package/dist/telemetry/index.js +5 -1
  221. package/dist/telemetry/spec.js +69 -1
  222. package/dist/telemetry/tracker.js +76 -1
  223. package/dist/tests/index.js +4 -1
  224. package/dist/tests/runner.js +150 -1
  225. package/dist/tests/spec.js +33 -1
  226. package/dist/themes.js +39 -1
  227. package/dist/workflow/adapters/db-adapter.js +83 -1
  228. package/dist/workflow/adapters/file-adapter.js +11 -1
  229. package/dist/workflow/adapters/index.js +5 -1
  230. package/dist/workflow/adapters/memory-store.js +58 -1
  231. package/dist/workflow/expression.js +98 -1
  232. package/dist/workflow/index.js +9 -1
  233. package/dist/workflow/runner.js +337 -1
  234. package/dist/workflow/sla-monitor.js +47 -1
  235. package/dist/workflow/spec.js +32 -1
  236. package/dist/workflow/validation.js +175 -1
  237. package/package.json +11 -4
@@ -1,8 +1,541 @@
1
- import{jsonSchemaForSpec as e}from"../jsonschema.js";import{isEmitDeclRef as t}from"../spec.js";const n={format:`full`,includeSchemas:!0,includeScenarios:!0,includeExamples:!0,includePolicy:!0,includeSideEffects:!0},r={...n,includeRelatedSpecs:!0,includeRelatedEvents:!0,includeRelatedPresentations:!0};function i(e){let t=e.meta,n=[];if(n.push(`# ${t.name} (v${t.version})`),n.push(``),n.push(`> ${t.description}`),n.push(``),n.push(`**Type:** ${t.kind} | **Stability:** ${t.stability}`),n.push(``),n.push(`## Goal`),n.push(``),n.push(t.goal),n.push(``),n.push(`## Context`),n.push(``),n.push(t.context),n.push(``),e.acceptance?.scenarios?.length){n.push(`## Acceptance Criteria`),n.push(``);for(let t of e.acceptance.scenarios){n.push(`### ${t.name}`),n.push(``),n.push(`**Given:**`);for(let e of t.given)n.push(`- ${e}`);n.push(``),n.push(`**When:**`);for(let e of t.when)n.push(`- ${e}`);n.push(``),n.push(`**Then:**`);for(let e of t.then)n.push(`- ${e}`);n.push(``)}}return n.join(`
2
- `)}function a(r,i={}){let a={...n,...i},o=r.meta,s=[];if(s.push(`# ${o.name}.v${o.version}`),s.push(``),s.push(`> ${o.description}`),s.push(``),s.push(`## Metadata`),s.push(``),s.push(`| Field | Value |`),s.push(`|-------|-------|`),s.push(`| Kind | ${o.kind} |`),s.push(`| Stability | ${o.stability} |`),s.push(`| Owners | ${o.owners.join(`, `)} |`),s.push(`| Tags | ${o.tags.join(`, `)} |`),s.push(``),s.push(`## Goal`),s.push(``),s.push(o.goal),s.push(``),s.push(`## Context`),s.push(``),s.push(o.context),s.push(``),a.includeSchemas){if(s.push(`## Input/Output`),s.push(``),r.io.input){s.push(`### Input Schema`),s.push(``),s.push("```json");try{let t=e(r);s.push(JSON.stringify(t.input??{},null,2))}catch{s.push(`// Schema generation not available`)}s.push("```"),s.push(``)}s.push(`### Output Schema`),s.push(``),s.push("```json");try{let t=e(r);s.push(JSON.stringify(t.output??{},null,2))}catch{s.push(`// Schema generation not available`)}if(s.push("```"),s.push(``),r.io.errors&&Object.keys(r.io.errors).length){s.push(`### Error Codes`),s.push(``),s.push(`| Code | HTTP | Description | When |`),s.push(`|------|------|-------------|------|`);for(let[e,t]of Object.entries(r.io.errors))s.push(`| \`${e}\` | ${t.http??400} | ${t.description} | ${t.when} |`);s.push(``)}}if(a.includePolicy&&(s.push(`## Policy`),s.push(``),s.push(`- **Auth Required:** ${r.policy.auth}`),s.push(`- **Idempotent:** ${r.policy.idempotent??o.kind===`query`}`),r.policy.rateLimit&&s.push(`- **Rate Limit:** ${r.policy.rateLimit.rpm} rpm per ${r.policy.rateLimit.key}`),r.policy.flags?.length&&s.push(`- **Feature Flags:** ${r.policy.flags.join(`, `)}`),r.policy.pii?.length&&s.push(`- **PII Fields:** ${r.policy.pii.join(`, `)}`),r.policy.escalate&&s.push(`- **Escalation:** ${r.policy.escalate}`),s.push(``)),a.includeSideEffects&&r.sideEffects){if(r.sideEffects.emits?.length){s.push(`## Events Emitted`),s.push(``);for(let e of r.sideEffects.emits)t(e)?s.push(`- \`${e.ref.name}.v${e.ref.version}\` — ${e.when}`):s.push(`- \`${e.name}.v${e.version}\` — ${e.when}`);s.push(``)}if(r.sideEffects.analytics?.length){s.push(`## Analytics Events`),s.push(``);for(let e of r.sideEffects.analytics)s.push(`- ${e}`);s.push(``)}}if(a.includeScenarios&&r.acceptance?.scenarios?.length){s.push(`## Acceptance Scenarios`),s.push(``);for(let e of r.acceptance.scenarios){s.push(`### ${e.name}`),s.push(``),s.push(`**Given:**`);for(let t of e.given)s.push(`- ${t}`);s.push(``),s.push(`**When:**`);for(let t of e.when)s.push(`- ${t}`);s.push(``),s.push(`**Then:**`);for(let t of e.then)s.push(`- ${t}`);s.push(``)}}if(a.includeExamples&&r.acceptance?.examples?.length){s.push(`## Examples`),s.push(``);for(let e of r.acceptance.examples)s.push(`### ${e.name}`),s.push(``),s.push(`**Input:**`),s.push("```json"),s.push(JSON.stringify(e.input,null,2)),s.push("```"),s.push(``),s.push(`**Output:**`),s.push("```json"),s.push(JSON.stringify(e.output,null,2)),s.push("```"),s.push(``)}return r.transport&&(s.push(`## Transport Configuration`),s.push(``),r.transport.rest&&s.push(`- **REST:** ${r.transport.rest.method??`POST`} ${r.transport.rest.path??`auto`}`),r.transport.gql&&s.push(`- **GraphQL:** ${r.transport.gql.field??`auto`}`),r.transport.mcp&&s.push(`- **MCP Tool:** ${r.transport.mcp.toolName??`auto`}`),s.push(``)),s.join(`
3
- `)}function o(e,t){let n=t?.taskType??`implement`,r=e.meta,i=[],o={implement:`Implement`,test:`Write tests for`,refactor:`Refactor`,review:`Review`}[n];if(i.push(`# Task: ${o} ${r.name}.v${r.version}`),i.push(``),i.push(`## Context`),i.push(``),i.push(`You are working on a ContractSpec-driven codebase. This spec defines a ${r.kind} operation.`),i.push(``),i.push(`**Goal:** ${r.goal}`),i.push(``),i.push(`**Background:** ${r.context}`),i.push(``),i.push(`## Specification`),i.push(``),i.push(a(e)),i.push(``),i.push(`## Instructions`),i.push(``),n===`implement`){if(i.push(`Implement this specification following these requirements:`),i.push(``),i.push("1. **Type Safety**: Use TypeScript with strict typing. No `any` types."),i.push(`2. **Input Validation**: Validate input against the schema before processing.`),i.push(`3. **Error Handling**: Implement all error cases defined in the spec.`),i.push(`4. **Events**: Emit events as specified in sideEffects.emits.`),i.push(`5. **Policy**: Respect auth, rate limits, and feature flags.`),i.push(`6. **Idempotency**: `+(e.policy.idempotent?`This operation MUST be idempotent.`:`This operation may have side effects.`)),i.push(``),e.policy.pii?.length){i.push(`**PII Handling**: The following fields contain PII and must be handled carefully:`);for(let t of e.policy.pii)i.push(`- ${t}`);i.push(``)}}else n===`test`?(i.push(`Write comprehensive tests for this specification:`),i.push(``),i.push(`1. Test all acceptance scenarios defined in the spec.`),i.push(`2. Test all error cases with appropriate assertions.`),i.push(`3. Test edge cases and boundary conditions.`),i.push(`4. Verify events are emitted correctly.`),i.push(`5. Use descriptive test names following the pattern: "should [behavior] when [condition]"`),i.push(``)):n===`refactor`?(i.push(`Refactor this implementation while preserving all behavior:`),i.push(``),i.push(`1. Maintain compliance with the specification.`),i.push(`2. Improve code clarity and maintainability.`),i.push(`3. Reduce complexity where possible.`),i.push(`4. Ensure all existing tests still pass.`),i.push(``)):n===`review`&&(i.push(`Review this implementation against the specification:`),i.push(``),i.push(`1. Verify input/output types match the schema.`),i.push(`2. Check all error cases are handled.`),i.push(`3. Verify events are emitted as specified.`),i.push(`4. Check policy compliance (auth, rate limits).`),i.push(`5. Report any deviations from the spec.`),i.push(``));return t?.existingCode&&(i.push(`## Existing Code`),i.push(``),i.push("```typescript"),i.push(t.existingCode),i.push("```"),i.push(``)),i.push(`## Expected Output`),i.push(``),n===`implement`||n===`refactor`?(i.push(`Provide a complete TypeScript implementation. Include:`),i.push(`- Type definitions for input/output`),i.push(`- Handler function with proper error handling`),i.push(`- JSDoc comments explaining the implementation`)):n===`test`?i.push(`Provide a complete test file using the testing framework available (prefer Vitest).`):n===`review`&&(i.push(`Provide a structured review with:`),i.push(`- Compliance status (pass/fail for each requirement)`),i.push(`- Issues found with severity (error/warning/info)`),i.push(`- Suggestions for improvement`)),i.push(``),i.join(`
4
- `)}function s(e,t,n={}){let i={...r,...n},o=e.meta,s=[];if(s.push(`# Feature: ${o.title??o.key}`),s.push(``),o.description&&(s.push(`> ${o.description}`),s.push(``)),s.push(`## Overview`),s.push(``),s.push(`- **Key:** \`${o.key}\``),s.push(`- **Stability:** ${o.stability}`),s.push(`- **Owners:** ${o.owners.join(`, `)}`),o.tags?.length&&s.push(`- **Tags:** ${o.tags.join(`, `)}`),s.push(``),e.operations?.length){s.push(`## Operations`),s.push(``),s.push(`| Name | Version | Type |`),s.push(`|------|---------|------|`);for(let n of e.operations){let e=(t?.specs?.getSpec(n.name,n.version))?.meta.kind??`unknown`;s.push(`| ${n.name} | v${n.version} | ${e} |`)}if(s.push(``),i.includeRelatedSpecs&&t?.specs){s.push(`### Operation Details`),s.push(``);for(let n of e.operations){let e=t.specs.getSpec(n.name,n.version);e&&(s.push(`---`),s.push(``),s.push(a(e,i)))}}}if(e.events?.length){s.push(`## Events`),s.push(``),s.push(`| Name | Version |`),s.push(`|------|---------|`);for(let t of e.events)s.push(`| ${t.name} | v${t.version} |`);s.push(``)}if(e.presentations?.length){s.push(`## Presentations`),s.push(``),s.push(`| Name | Version |`),s.push(`|------|---------|`);for(let t of e.presentations)s.push(`| ${t.name} | v${t.version} |`);if(s.push(``),i.includeRelatedPresentations&&t?.presentations){s.push(`### Presentation Details`),s.push(``);for(let n of e.presentations){let e=t.presentations.get(n.name,n.version);e&&(s.push(`#### ${n.name}.v${n.version}`),s.push(``),s.push(`- **Kind:** ${e.content.kind??`unknown`}`),`componentKey`in e.content&&s.push(`- **Component:** ${e.content.componentKey}`),s.push(``))}}}if(e.capabilities){if(e.capabilities.provides?.length){s.push(`## Capabilities Provided`),s.push(``);for(let t of e.capabilities.provides)s.push(`- \`${t.key}.v${t.version}\``);s.push(``)}if(e.capabilities.requires?.length){s.push(`## Capabilities Required`),s.push(``);for(let t of e.capabilities.requires)s.push(`- \`${t.key}\`${t.version?`.v${t.version}`:``} (${t.optional?`optional`:`required`})`);s.push(``)}}return s.join(`
5
- `)}function c(e){let t=e.meta,n=[];n.push(`# Presentation: ${t.name}.v${t.version}`),n.push(``),t.description&&(n.push(`> ${t.description}`),n.push(``)),n.push(`## Metadata`),n.push(``),n.push(`- **Name:** ${t.name}`),n.push(`- **Version:** ${t.version}`),t.stability&&n.push(`- **Stability:** ${t.stability}`),t.owners?.length&&n.push(`- **Owners:** ${t.owners.join(`, `)}`),t.tags?.length&&n.push(`- **Tags:** ${t.tags.join(`, `)}`),n.push(``),n.push(`## Source`),n.push(``),n.push(`- **Type:** ${e.source.type}`),e.source.type===`component`&&(n.push(`- **Framework:** ${e.source.framework}`),n.push(`- **Component Key:** ${e.source.componentKey}`)),n.push(``),n.push(`## Supported Targets`),n.push(``);for(let t of e.targets)n.push(`- ${t}`);return n.push(``),e.policy&&(n.push(`## Policy`),n.push(``),e.policy.flags?.length&&n.push(`- **Feature Flags:** ${e.policy.flags.join(`, `)}`),e.policy.pii?.length&&n.push(`- **PII Fields:** ${e.policy.pii.join(`, `)}`),n.push(``)),n.join(`
6
- `)}function l(e){let t=[];t.push(`# Event: ${e.name}.v${e.version}`),t.push(``),t.push(`## Metadata`),t.push(``),t.push(`- **Name:** ${e.name}`),t.push(`- **Version:** ${e.version}`),e.description&&t.push(`- **Description:** ${e.description}`),t.push(``),t.push(`## Payload Schema`),t.push(``),t.push("```json");try{let n=e.payload.getZod();if(`shape`in n&&n.shape){let e=n.shape,r=Object.keys(e);t.push(JSON.stringify({fields:r},null,2))}else t.push(`// Payload schema available at runtime`)}catch{t.push(`// Schema details available at runtime`)}return t.push("```"),t.push(``),t.join(`
7
- `)}function u(e){let t=[];if(t.push(`# ${e.title}`),t.push(``),e.summary&&(t.push(`> ${e.summary}`),t.push(``)),t.push(`## Metadata`),t.push(``),t.push(`- **ID:** ${e.id}`),t.push(`- **Kind:** ${e.kind??`reference`}`),t.push(`- **Visibility:** ${e.visibility??`public`}`),e.tags?.length&&t.push(`- **Tags:** ${e.tags.join(`, `)}`),e.owners?.length&&t.push(`- **Owners:** ${e.owners.join(`, `)}`),e.domain&&t.push(`- **Domain:** ${e.domain}`),t.push(``),t.push(`## Content`),t.push(``),t.push(e.body),t.push(``),e.links?.length){t.push(`## Related Links`),t.push(``);for(let n of e.links)t.push(`- [${n.label}](${n.href})`);t.push(``)}return t.join(`
8
- `)}function d(e,t={}){let n=t.format??`full`,r;switch(n){case`context`:r=i(e);break;case`prompt`:r=o(e);break;case`full`:default:r=a(e,t);break}return{spec:e,markdown:r,format:n,meta:{specName:e.meta.name,specVersion:e.meta.version,exportedAt:new Date().toISOString(),wordCount:r.split(/\s+/).length}}}function f(e,t,n={}){let r=n.format??`full`;return{feature:e,markdown:s(e,t,n),format:r,includedSpecs:e.operations?.map(e=>`${e.name}.v${e.version}`)??[],includedEvents:e.events?.map(e=>`${e.name}.v${e.version}`)??[],includedPresentations:e.presentations?.map(e=>`${e.name}.v${e.version}`)??[]}}export{u as docBlockToMarkdown,l as eventToMarkdown,f as exportFeature,d as exportSpec,s as featureToMarkdown,c as presentationToMarkdown,o as specToAgentPrompt,i as specToContextMarkdown,a as specToFullMarkdown};
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{docBlockToMarkdown as e,eventToMarkdown as t,exportFeature as n,exportSpec as r,featureToMarkdown as i,presentationToMarkdown as a,specToAgentPrompt as o,specToContextMarkdown as s,specToFullMarkdown as c}from"./exporters.js";import{AGENT_SYSTEM_PROMPTS as l,formatPlanForAgent as u,generateFixViolationsPrompt as d,generateImplementationPlan as f,generateImplementationPrompt as p,generateReviewPrompt as m,generateTestPrompt as h,generateVerificationPrompt as g}from"./prompts.js";export{l as AGENT_SYSTEM_PROMPTS,e as docBlockToMarkdown,t as eventToMarkdown,n as exportFeature,r as exportSpec,i as featureToMarkdown,u as formatPlanForAgent,d as generateFixViolationsPrompt,f as generateImplementationPlan,p as generateImplementationPrompt,m as generateReviewPrompt,h as generateTestPrompt,g as generateVerificationPrompt,a as presentationToMarkdown,o as specToAgentPrompt,s as specToContextMarkdown,c as specToFullMarkdown};
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 };