@lssm/bundle.contractspec-workspace 0.0.0-canary-20251217060834 → 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 (269) hide show
  1. package/dist/_virtual/rolldown_runtime.js +22 -1
  2. package/dist/adapters/ai.js +82 -1
  3. package/dist/adapters/factory.js +36 -1
  4. package/dist/adapters/fs.js +118 -1
  5. package/dist/adapters/git.js +54 -1
  6. package/dist/adapters/index.js +7 -1
  7. package/dist/adapters/logger.js +80 -1
  8. package/dist/adapters/watcher.js +69 -1
  9. package/dist/adapters/workspace.js +190 -2
  10. package/dist/ai/agents/claude-code-agent.js +146 -9
  11. package/dist/ai/agents/cursor-agent.js +286 -17
  12. package/dist/ai/agents/index.js +5 -1
  13. package/dist/ai/agents/openai-codex-agent.js +140 -8
  14. package/dist/ai/agents/orchestrator.js +142 -1
  15. package/dist/ai/agents/simple-agent.js +80 -4
  16. package/dist/ai/client.js +162 -1
  17. package/dist/ai/index.js +27 -1
  18. package/dist/ai/prompts/code-generation.js +55 -13
  19. package/dist/ai/prompts/index.js +12 -1
  20. package/dist/ai/prompts/spec-creation.js +61 -20
  21. package/dist/ai/providers.js +40 -1
  22. package/dist/formatters/index.js +18 -1
  23. package/dist/formatters/json.js +71 -1
  24. package/dist/formatters/sarif.js +163 -1
  25. package/dist/formatters/text.js +208 -2
  26. package/dist/index.d.ts +0 -3
  27. package/dist/index.js +81 -1
  28. package/dist/libs/ai-providers/dist/factory.js +154 -0
  29. package/dist/libs/ai-providers/dist/index.js +4 -0
  30. package/dist/libs/ai-providers/dist/legacy.js +72 -0
  31. package/dist/libs/ai-providers/dist/models.js +287 -0
  32. package/dist/libs/ai-providers/dist/validation.js +1 -0
  33. package/dist/libs/contracts/dist/capabilities/openbanking.js +88 -0
  34. package/dist/libs/contracts/dist/client/index.js +5 -0
  35. package/dist/libs/contracts/dist/client/react/feature-render.js +2 -0
  36. package/dist/libs/contracts/dist/client/react/form-render.js +4 -0
  37. package/dist/libs/contracts/dist/client/react/index.js +4 -0
  38. package/dist/libs/contracts/dist/contract-registry/index.js +1 -0
  39. package/dist/libs/contracts/dist/contract-registry/schemas.js +60 -0
  40. package/dist/libs/contracts/dist/docs/PUBLISHING.docblock.js +16 -0
  41. package/dist/libs/contracts/dist/docs/accessibility_wcag_compliance_specs.docblock.js +16 -0
  42. package/dist/libs/contracts/dist/docs/index.js +29 -0
  43. package/dist/libs/contracts/dist/docs/presentations.js +71 -0
  44. package/dist/libs/contracts/dist/docs/registry.js +44 -0
  45. package/dist/libs/contracts/dist/docs/tech/PHASE_1_QUICKSTART.docblock.js +16 -0
  46. package/dist/libs/contracts/dist/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS.docblock.js +16 -0
  47. package/dist/libs/contracts/dist/docs/tech/PHASE_3_AUTO_EVOLUTION.docblock.js +16 -0
  48. package/dist/libs/contracts/dist/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js +16 -0
  49. package/dist/libs/contracts/dist/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js +16 -0
  50. package/dist/libs/contracts/dist/docs/tech/auth/better-auth-nextjs.docblock.js +80 -0
  51. package/dist/libs/contracts/dist/docs/tech/contracts/openapi-export.docblock.js +57 -0
  52. package/dist/libs/contracts/dist/docs/tech/lifecycle-stage-system.docblock.js +16 -0
  53. package/dist/libs/contracts/dist/docs/tech/llm/llm-integration.docblock.js +357 -0
  54. package/dist/libs/contracts/dist/docs/tech/mcp-endpoints.docblock.js +37 -0
  55. package/dist/libs/contracts/dist/docs/tech/presentation-runtime.docblock.js +16 -0
  56. package/dist/libs/contracts/dist/docs/tech/schema/README.docblock.js +20 -0
  57. package/dist/libs/contracts/dist/docs/tech/studio/learning-events.docblock.js +48 -0
  58. package/dist/libs/contracts/dist/docs/tech/studio/learning-journeys.docblock.js +79 -0
  59. package/dist/libs/contracts/dist/docs/tech/studio/platform-admin-panel.docblock.js +84 -0
  60. package/dist/libs/contracts/dist/docs/tech/studio/project-access-teams.docblock.js +45 -0
  61. package/dist/libs/contracts/dist/docs/tech/studio/project-routing.docblock.js +67 -0
  62. package/dist/libs/contracts/dist/docs/tech/studio/sandbox-unlogged.docblock.js +40 -0
  63. package/dist/libs/contracts/dist/docs/tech/studio/team-invitations.docblock.js +69 -0
  64. package/dist/libs/contracts/dist/docs/tech/studio/workspace-ops.docblock.js +47 -0
  65. package/dist/libs/contracts/dist/docs/tech/studio/workspaces.docblock.js +62 -0
  66. package/dist/libs/contracts/dist/docs/tech/telemetry-ingest.docblock.js +155 -0
  67. package/dist/libs/contracts/dist/docs/tech/templates/runtime.docblock.js +20 -0
  68. package/dist/libs/contracts/dist/docs/tech/vscode-extension.docblock.js +101 -0
  69. package/dist/libs/contracts/dist/docs/tech/workflows/overview.docblock.js +20 -0
  70. package/dist/libs/contracts/dist/events.js +8 -0
  71. package/dist/libs/contracts/dist/experiments/evaluator.js +1 -0
  72. package/dist/libs/contracts/dist/index.js +72 -0
  73. package/dist/libs/contracts/dist/install.js +2 -0
  74. package/dist/libs/contracts/dist/integrations/contracts.js +377 -0
  75. package/dist/libs/contracts/dist/integrations/index.js +18 -0
  76. package/dist/libs/contracts/dist/integrations/openbanking/contracts/accounts.js +228 -0
  77. package/dist/libs/contracts/dist/integrations/openbanking/contracts/balances.js +159 -0
  78. package/dist/libs/contracts/dist/integrations/openbanking/contracts/index.js +3 -0
  79. package/dist/libs/contracts/dist/integrations/openbanking/contracts/transactions.js +210 -0
  80. package/dist/libs/contracts/dist/integrations/openbanking/models.js +242 -0
  81. package/dist/libs/contracts/dist/integrations/openbanking/telemetry.js +13 -0
  82. package/dist/libs/contracts/dist/integrations/providers/elevenlabs.js +52 -0
  83. package/dist/libs/contracts/dist/integrations/providers/gcs-storage.js +75 -0
  84. package/dist/libs/contracts/dist/integrations/providers/gmail.js +87 -0
  85. package/dist/libs/contracts/dist/integrations/providers/google-calendar.js +66 -0
  86. package/dist/libs/contracts/dist/integrations/providers/index.js +11 -0
  87. package/dist/libs/contracts/dist/integrations/providers/mistral.js +68 -0
  88. package/dist/libs/contracts/dist/integrations/providers/postmark.js +68 -0
  89. package/dist/libs/contracts/dist/integrations/providers/powens.js +116 -0
  90. package/dist/libs/contracts/dist/integrations/providers/qdrant.js +73 -0
  91. package/dist/libs/contracts/dist/integrations/providers/registry.js +10 -0
  92. package/dist/libs/contracts/dist/integrations/providers/stripe.js +83 -0
  93. package/dist/libs/contracts/dist/integrations/providers/twilio-sms.js +61 -0
  94. package/dist/libs/contracts/dist/jsonschema.js +24 -0
  95. package/dist/libs/contracts/dist/knowledge/contracts.js +306 -0
  96. package/dist/libs/contracts/dist/knowledge/index.js +7 -0
  97. package/dist/libs/contracts/dist/knowledge/spaces/email-threads.js +34 -0
  98. package/dist/libs/contracts/dist/knowledge/spaces/financial-docs.js +34 -0
  99. package/dist/libs/contracts/dist/knowledge/spaces/financial-overview.js +38 -0
  100. package/dist/libs/contracts/dist/knowledge/spaces/index.js +6 -0
  101. package/dist/libs/contracts/dist/knowledge/spaces/product-canon.js +34 -0
  102. package/dist/libs/contracts/dist/knowledge/spaces/support-faq.js +37 -0
  103. package/dist/libs/contracts/dist/knowledge/spaces/uploaded-docs.js +34 -0
  104. package/dist/libs/contracts/dist/llm/exporters.js +352 -0
  105. package/dist/libs/contracts/dist/llm/index.js +2 -0
  106. package/dist/libs/contracts/dist/llm/prompts.js +211 -0
  107. package/dist/libs/contracts/dist/onboarding-base.js +196 -0
  108. package/dist/libs/contracts/dist/openapi.js +75 -0
  109. package/dist/libs/contracts/dist/ownership.js +21 -0
  110. package/dist/libs/contracts/dist/presentations.js +1 -0
  111. package/dist/libs/contracts/dist/presentations.v2.js +11 -0
  112. package/dist/libs/contracts/dist/prompt.js +1 -0
  113. package/dist/libs/contracts/dist/promptRegistry.js +1 -0
  114. package/dist/libs/contracts/dist/regenerator/index.js +2 -0
  115. package/dist/libs/contracts/dist/regenerator/service.js +92 -0
  116. package/dist/libs/contracts/dist/regenerator/utils.js +51 -0
  117. package/dist/libs/contracts/dist/registry.js +208 -0
  118. package/dist/libs/contracts/dist/resources.js +1 -0
  119. package/dist/libs/contracts/dist/schema/dist/EnumType.js +2 -0
  120. package/dist/libs/contracts/dist/schema/dist/FieldType.js +49 -0
  121. package/dist/libs/contracts/dist/schema/dist/ScalarTypeEnum.js +236 -0
  122. package/dist/libs/contracts/dist/schema/dist/SchemaModel.js +34 -0
  123. package/dist/libs/contracts/dist/schema/dist/entity/defineEntity.js +1 -0
  124. package/dist/libs/contracts/dist/schema/dist/entity/index.js +2 -0
  125. package/dist/libs/contracts/dist/schema/dist/entity/types.js +1 -0
  126. package/dist/libs/contracts/dist/schema/dist/index.js +6 -0
  127. package/dist/libs/contracts/dist/server/graphql-pothos.js +6 -0
  128. package/dist/libs/contracts/dist/server/index.js +8 -0
  129. package/dist/libs/contracts/dist/server/mcp/createMcpServer.js +4 -0
  130. package/dist/libs/contracts/dist/server/mcp/registerPresentations.js +2 -0
  131. package/dist/libs/contracts/dist/server/mcp/registerPrompts.js +1 -0
  132. package/dist/libs/contracts/dist/server/mcp/registerResources.js +2 -0
  133. package/dist/libs/contracts/dist/server/mcp/registerTools.js +1 -0
  134. package/dist/libs/contracts/dist/server/provider-mcp.js +1 -0
  135. package/dist/libs/contracts/dist/server/rest-elysia.js +1 -0
  136. package/dist/libs/contracts/dist/server/rest-express.js +1 -0
  137. package/dist/libs/contracts/dist/server/rest-generic.js +1 -0
  138. package/dist/libs/contracts/dist/server/rest-next-app.js +1 -0
  139. package/dist/libs/contracts/dist/server/rest-next-pages.js +1 -0
  140. package/dist/libs/contracts/dist/spec.js +35 -0
  141. package/dist/libs/contracts/dist/telemetry/index.js +1 -0
  142. package/dist/libs/contracts/dist/telemetry/tracker.js +1 -0
  143. package/dist/libs/contracts/dist/tests/index.js +1 -0
  144. package/dist/libs/contracts/dist/tests/runner.js +150 -0
  145. package/dist/libs/contracts/dist/workflow/index.js +1 -0
  146. package/dist/libs/contracts/dist/workflow/runner.js +1 -0
  147. package/dist/libs/contracts-transformers/dist/common/utils.js +47 -0
  148. package/dist/libs/contracts-transformers/dist/openapi/exporter.js +1 -0
  149. package/dist/libs/contracts-transformers/dist/openapi/importer.js +255 -0
  150. package/dist/libs/contracts-transformers/dist/openapi/index.js +4 -0
  151. package/dist/libs/contracts-transformers/dist/openapi/parser.js +231 -0
  152. package/dist/libs/contracts-transformers/dist/openapi/schema-converter.js +201 -0
  153. package/dist/modules/contractspec-workspace/dist/ai/code-generation.js +137 -0
  154. package/dist/modules/contractspec-workspace/dist/ai/spec-creation.js +101 -0
  155. package/dist/modules/contractspec-workspace/dist/analysis/deps/graph.js +84 -0
  156. package/dist/modules/contractspec-workspace/dist/analysis/deps/parse-imports.js +30 -0
  157. package/dist/modules/contractspec-workspace/dist/analysis/diff/semantic.js +96 -0
  158. package/dist/modules/contractspec-workspace/dist/analysis/feature-scan.js +151 -0
  159. package/dist/modules/contractspec-workspace/dist/analysis/spec-scan.js +344 -0
  160. package/dist/modules/contractspec-workspace/dist/analysis/validate/spec-structure.js +122 -0
  161. package/dist/modules/contractspec-workspace/dist/templates/app-config.js +105 -0
  162. package/dist/modules/contractspec-workspace/dist/templates/data-view.js +68 -0
  163. package/dist/modules/contractspec-workspace/dist/templates/event.js +38 -0
  164. package/dist/modules/contractspec-workspace/dist/templates/experiment.js +87 -0
  165. package/dist/modules/contractspec-workspace/dist/templates/handler.js +95 -0
  166. package/dist/modules/contractspec-workspace/dist/templates/integration-utils.js +104 -0
  167. package/dist/modules/contractspec-workspace/dist/templates/integration.js +62 -0
  168. package/dist/modules/contractspec-workspace/dist/templates/knowledge.js +68 -0
  169. package/dist/modules/contractspec-workspace/dist/templates/migration.js +60 -0
  170. package/dist/modules/contractspec-workspace/dist/templates/operation.js +100 -0
  171. package/dist/modules/contractspec-workspace/dist/templates/presentation.js +78 -0
  172. package/dist/modules/contractspec-workspace/dist/templates/telemetry.js +89 -0
  173. package/dist/modules/contractspec-workspace/dist/templates/utils.js +38 -0
  174. package/dist/modules/contractspec-workspace/dist/templates/workflow-runner.js +48 -0
  175. package/dist/modules/contractspec-workspace/dist/templates/workflow.js +67 -0
  176. package/dist/modules/contractspec-workspace/dist/types/generation-types.js +20 -0
  177. package/dist/services/agent-guide/adapters/claude-code.js +144 -3
  178. package/dist/services/agent-guide/adapters/cursor-cli.js +135 -3
  179. package/dist/services/agent-guide/adapters/generic-mcp.js +159 -3
  180. package/dist/services/agent-guide/adapters/index.js +30 -1
  181. package/dist/services/agent-guide/agent-guide-service.js +148 -1
  182. package/dist/services/agent-guide/index.js +5 -1
  183. package/dist/services/build.js +140 -1
  184. package/dist/services/ci-check/ci-check-service.js +393 -1
  185. package/dist/services/ci-check/index.js +2 -1
  186. package/dist/services/ci-check/types.js +28 -1
  187. package/dist/services/clean.js +71 -1
  188. package/dist/services/config.js +76 -1
  189. package/dist/services/deps.js +62 -1
  190. package/dist/services/diff.js +33 -1
  191. package/dist/services/doctor/checks/ai.js +118 -2
  192. package/dist/services/doctor/checks/cli.js +146 -1
  193. package/dist/services/doctor/checks/config.js +170 -1
  194. package/dist/services/doctor/checks/deps.js +180 -1
  195. package/dist/services/doctor/checks/index.js +6 -1
  196. package/dist/services/doctor/checks/mcp.js +144 -1
  197. package/dist/services/doctor/checks/workspace.js +243 -1
  198. package/dist/services/doctor/doctor-service.js +115 -2
  199. package/dist/services/doctor/index.js +2 -1
  200. package/dist/services/doctor/types.js +26 -1
  201. package/dist/services/implementation/discovery.js +143 -2
  202. package/dist/services/implementation/index.js +2 -1
  203. package/dist/services/implementation/resolver.js +223 -1
  204. package/dist/services/index.js +53 -1
  205. package/dist/services/integrity-diagram.js +274 -6
  206. package/dist/services/integrity.js +272 -1
  207. package/dist/services/list.js +35 -1
  208. package/dist/services/openapi/export-service.js +51 -2
  209. package/dist/services/openapi/import-service.js +75 -1
  210. package/dist/services/openapi/index.js +4 -1
  211. package/dist/services/openapi/sync-service.js +121 -1
  212. package/dist/services/openapi/validate-service.js +130 -1
  213. package/dist/services/regenerator.js +23 -1
  214. package/dist/services/registry.js +73 -1
  215. package/dist/services/setup/config-generators.js +113 -26
  216. package/dist/services/setup/file-merger.js +60 -2
  217. package/dist/services/setup/index.js +4 -1
  218. package/dist/services/setup/setup-service.js +95 -1
  219. package/dist/services/setup/targets/agents-md.js +46 -1
  220. package/dist/services/setup/targets/cli-config.js +59 -1
  221. package/dist/services/setup/targets/cursor-rules.js +47 -1
  222. package/dist/services/setup/targets/mcp-claude.js +59 -1
  223. package/dist/services/setup/targets/mcp-cursor.js +58 -1
  224. package/dist/services/setup/targets/vscode-settings.js +62 -1
  225. package/dist/services/setup/types.js +26 -1
  226. package/dist/services/sync.js +62 -1
  227. package/dist/services/test.js +30 -1
  228. package/dist/services/validate-implementation.js +69 -1
  229. package/dist/services/validate.js +47 -1
  230. package/dist/services/verification-cache/adapters/filesystem.js +121 -1
  231. package/dist/services/verification-cache/adapters/in-memory.js +45 -1
  232. package/dist/services/verification-cache/adapters/index.js +3 -1
  233. package/dist/services/verification-cache/adapters/workspace-state.js +90 -1
  234. package/dist/services/verification-cache/cache-service.js +255 -1
  235. package/dist/services/verification-cache/index.js +6 -1
  236. package/dist/services/verification-cache/types.js +15 -1
  237. package/dist/services/verify/ai-verifier.js +336 -9
  238. package/dist/services/verify/behavior-verifier.js +185 -1
  239. package/dist/services/verify/index.js +4 -1
  240. package/dist/services/verify/structure-verifier.js +195 -2
  241. package/dist/services/verify/verify-service.js +203 -3
  242. package/dist/services/watch.js +31 -1
  243. package/dist/services/workspace-info.js +102 -2
  244. package/dist/templates/app-config.template.js +101 -28
  245. package/dist/templates/data-view.template.js +42 -27
  246. package/dist/templates/event.template.js +29 -14
  247. package/dist/templates/experiment.template.js +77 -51
  248. package/dist/templates/handler.template.js +53 -17
  249. package/dist/templates/index.js +36 -1
  250. package/dist/templates/integration.template.js +134 -50
  251. package/dist/templates/knowledge.template.js +62 -21
  252. package/dist/templates/migration.template.js +50 -26
  253. package/dist/templates/operation.template.js +44 -28
  254. package/dist/templates/presentation.template.js +46 -20
  255. package/dist/templates/telemetry.template.js +74 -53
  256. package/dist/templates/workflow-runner.template.js +12 -6
  257. package/dist/templates/workflow.template.js +51 -24
  258. package/package.json +13 -9
  259. package/dist/adapters/index.d.ts +0 -7
  260. package/dist/ports/index.d.ts +0 -5
  261. package/dist/services/agent-guide/index.d.ts +0 -6
  262. package/dist/services/ci-check/index.d.ts +0 -2
  263. package/dist/services/doctor/index.d.ts +0 -2
  264. package/dist/services/implementation/index.d.ts +0 -3
  265. package/dist/services/index.d.ts +0 -56
  266. package/dist/services/openapi/index.d.ts +0 -5
  267. package/dist/services/verification-cache/adapters/index.d.ts +0 -3
  268. package/dist/services/verification-cache/index.d.ts +0 -6
  269. package/dist/services/verify/index.d.ts +0 -5
@@ -0,0 +1,89 @@
1
+ import { toPascalCase } from "./utils.js";
2
+
3
+ //#region ../../modules/contractspec-workspace/dist/templates/telemetry.js
4
+ function generateTelemetrySpec(data) {
5
+ const specVar = toPascalCase(data.name.split(".").pop() ?? "Telemetry") + "Telemetry";
6
+ const providers = data.providers?.length ? `providers: [
7
+ ${data.providers.map((provider) => ` {
8
+ type: '${provider.type}',
9
+ config: ${formatConfigValue(provider.config)},
10
+ }`).join(",\n")}
11
+ ],` : "";
12
+ const events = data.events.map((event) => {
13
+ const properties = event.properties.map((prop) => ` '${prop.name}': {
14
+ type: '${prop.type}',
15
+ ${prop.required ? "required: true," : ""}
16
+ ${prop.pii ? "pii: true," : ""}
17
+ ${prop.redact ? "redact: true," : ""}
18
+ ${prop.description ? `description: '${escapeString(prop.description)}',` : ""}
19
+ }`).join(",\n");
20
+ const anomalyRules = event.anomalyRules?.length ? ` anomalyDetection: {
21
+ enabled: true,
22
+ ${typeof event.anomalyMinimumSample === "number" ? `minimumSample: ${event.anomalyMinimumSample},` : ""}
23
+ thresholds: [
24
+ ${event.anomalyRules.map((rule) => ` {
25
+ metric: '${escapeString(rule.metric)}',
26
+ ${typeof rule.min === "number" ? `min: ${rule.min},` : ""}
27
+ ${typeof rule.max === "number" ? `max: ${rule.max},` : ""}
28
+ }`).join(",\n")}
29
+ ],
30
+ actions: [${(event.anomalyActions ?? []).map((action) => `'${action}'`).join(", ")}],
31
+ },` : event.anomalyEnabled ? ` anomalyDetection: {
32
+ enabled: true,
33
+ ${typeof event.anomalyMinimumSample === "number" ? `minimumSample: ${event.anomalyMinimumSample},` : ""}
34
+ },` : "";
35
+ return ` {
36
+ name: '${escapeString(event.name)}',
37
+ version: ${event.version},
38
+ semantics: {
39
+ what: '${escapeString(event.what)}',
40
+ ${event.who ? `who: '${escapeString(event.who)}',` : ""}
41
+ ${event.why ? `why: '${escapeString(event.why)}',` : ""}
42
+ },
43
+ privacy: '${event.privacy}',
44
+ properties: {
45
+ ${properties}
46
+ },
47
+ ${typeof event.retentionDays === "number" ? `retention: { days: ${event.retentionDays}, ${event.retentionPolicy ? `policy: '${event.retentionPolicy}'` : ""} },` : ""}
48
+ ${typeof event.samplingRate === "number" ? `sampling: { rate: ${event.samplingRate}${event.samplingConditions ? `, conditions: ['${escapeString(event.samplingConditions)}']` : ""} },` : ""}
49
+ ${anomalyRules}
50
+ ${event.tags?.length ? `tags: [${event.tags.map((tag) => `'${escapeString(tag)}'`).join(", ")}],` : ""}
51
+ }`;
52
+ }).join(",\n");
53
+ return `import type { TelemetrySpec } from '@lssm/lib.contracts/telemetry';
54
+
55
+ export const ${specVar}: TelemetrySpec = {
56
+ meta: {
57
+ name: '${escapeString(data.name)}',
58
+ version: ${data.version},
59
+ title: '${escapeString(data.name)} telemetry',
60
+ description: '${escapeString(data.description || "Describe the purpose of this telemetry spec.")}',
61
+ domain: '${escapeString(data.domain)}',
62
+ owners: [${data.owners.map((owner) => `'${escapeString(owner)}'`).join(", ")}],
63
+ tags: [${data.tags.map((tag) => `'${escapeString(tag)}'`).join(", ")}],
64
+ stability: '${data.stability}',
65
+ },
66
+ config: {
67
+ ${typeof data.defaultRetentionDays === "number" ? `defaultRetentionDays: ${data.defaultRetentionDays},` : ""}
68
+ ${typeof data.defaultSamplingRate === "number" ? `defaultSamplingRate: ${data.defaultSamplingRate},` : ""}
69
+ ${data.anomalyEnabled ? `anomalyDetection: { enabled: true${typeof data.anomalyCheckIntervalMs === "number" ? `, checkIntervalMs: ${data.anomalyCheckIntervalMs}` : ""} },` : ""}
70
+ ${providers}
71
+ },
72
+ events: [
73
+ ${events}
74
+ ],
75
+ };
76
+ `;
77
+ }
78
+ function escapeString(value) {
79
+ return value.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
80
+ }
81
+ function formatConfigValue(value) {
82
+ const trimmed = value.trim();
83
+ if (!trimmed) return "{}";
84
+ if (trimmed.startsWith("{") && trimmed.endsWith("}") || trimmed.startsWith("[") && trimmed.endsWith("]")) return trimmed;
85
+ return `'${escapeString(trimmed)}'`;
86
+ }
87
+
88
+ //#endregion
89
+ export { generateTelemetrySpec };
@@ -0,0 +1,38 @@
1
+ //#region ../../modules/contractspec-workspace/dist/templates/utils.js
2
+ /**
3
+ * Utility functions for template generation.
4
+ */
5
+ /**
6
+ * Convert string to camelCase.
7
+ */
8
+ function toCamelCase(str) {
9
+ const pascal = toPascalCase(str);
10
+ return pascal.charAt(0).toLowerCase() + pascal.slice(1);
11
+ }
12
+ /**
13
+ * Convert string to PascalCase.
14
+ */
15
+ function toPascalCase(str) {
16
+ return str.split(/[-_.]/).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
17
+ }
18
+ /**
19
+ * Convert string to kebab-case.
20
+ */
21
+ function toKebabCase(str) {
22
+ return str.replace(/\./g, "-").replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
23
+ }
24
+ /**
25
+ * Capitalize first letter.
26
+ */
27
+ function capitalize(str) {
28
+ return str.charAt(0).toUpperCase() + str.slice(1);
29
+ }
30
+ /**
31
+ * Escape single quotes in string.
32
+ */
33
+ function escapeString(value) {
34
+ return value.replace(/'/g, "\\'");
35
+ }
36
+
37
+ //#endregion
38
+ export { capitalize, escapeString, toCamelCase, toKebabCase, toPascalCase };
@@ -0,0 +1,48 @@
1
+ //#region ../../modules/contractspec-workspace/dist/templates/workflow-runner.js
2
+ function generateWorkflowRunnerTemplate({ exportName, specImportPath, runnerName, workflowName }) {
3
+ return `import {
4
+ InMemoryStateStore,
5
+ WorkflowRegistry,
6
+ WorkflowRunner,
7
+ } from '@lssm/lib.contracts/workflow';
8
+ import { ${exportName} } from '${specImportPath}';
9
+
10
+ /**
11
+ * Runner wiring for ${workflowName}.
12
+ *
13
+ * TODO:
14
+ * - Replace the in-memory state store with a persistent adapter if needed.
15
+ * - Implement opExecutor to invoke the correct contract handlers.
16
+ * - Wire eventEmitter to telemetry sinks.
17
+ */
18
+ const registry = new WorkflowRegistry();
19
+ registry.register(${exportName});
20
+
21
+ const stateStore = new InMemoryStateStore();
22
+
23
+ export const ${runnerName} = new WorkflowRunner({
24
+ registry,
25
+ stateStore,
26
+ opExecutor: async (operation, input, ctx) => {
27
+ // TODO: route to the appropriate contract handler
28
+ // Example: return contractRegistry.execute(operation.name, operation.version, input, ctx);
29
+ throw new Error(
30
+ \`opExecutor for \${operation.name}.v\${operation.version} is not implemented\`
31
+ );
32
+ },
33
+ // appConfigProvider: async (state) => {
34
+ // // TODO: return the ResolvedAppConfig for this workflow run (tenant/environment)
35
+ // return undefined;
36
+ // },
37
+ // enforceCapabilities: async (operation, context) => {
38
+ // // TODO: ensure required capabilities are satisfied using context.integrations/context.resolvedAppConfig
39
+ // },
40
+ eventEmitter: (_event, _payload) => {
41
+ // TODO: forward workflow events to telemetry or logging sinks
42
+ },
43
+ });
44
+ `;
45
+ }
46
+
47
+ //#endregion
48
+ export { generateWorkflowRunnerTemplate };
@@ -0,0 +1,67 @@
1
+ import { escapeString, toPascalCase } from "./utils.js";
2
+
3
+ //#region ../../modules/contractspec-workspace/dist/templates/workflow.js
4
+ /**
5
+ * Generate workflow spec TypeScript code.
6
+ */
7
+ function generateWorkflowSpec(data) {
8
+ const specVarName = toPascalCase(data.name.split(".").pop() ?? "Workflow") + "Workflow";
9
+ const stepsCode = data.steps.map((step) => formatStep(step)).join(",\n");
10
+ const transitionsCode = data.transitions.map((transition) => ` {
11
+ from: '${transition.from}',
12
+ to: '${transition.to}',
13
+ ${transition.condition ? ` condition: '${escapeString(transition.condition)}',` : ""}
14
+ }`).join(",\n");
15
+ return `import type { WorkflowSpec } from '@lssm/lib.contracts/workflow';
16
+
17
+ /**
18
+ * Workflow generated via contractspec CLI.
19
+ * TODO:
20
+ * - Review step definitions and descriptions.
21
+ * - Wire automation steps to actual operations.
22
+ * - Provide form renderers for human steps.
23
+ * - Add guards/conditions as needed.
24
+ */
25
+ export const ${specVarName}: WorkflowSpec = {
26
+ meta: {
27
+ name: '${data.name}',
28
+ version: ${data.version},
29
+ title: '${escapeString(data.title)}',
30
+ description: '${escapeString(data.description)}',
31
+ domain: '${escapeString(data.domain)}',
32
+ stability: '${data.stability}',
33
+ owners: [${data.owners.map((owner) => `'${owner}'`).join(", ")}],
34
+ tags: [${data.tags.map((tag) => `'${tag}'`).join(", ")}],
35
+ },
36
+ definition: {
37
+ ${data.entryStepId ? ` entryStepId: '${data.entryStepId}',\n` : ""} steps: [
38
+ ${stepsCode}
39
+ ],
40
+ transitions: [
41
+ ${transitionsCode}
42
+ ],
43
+ },
44
+ ${data.policyFlags.length > 0 ? `policy: {
45
+ flags: [${data.policyFlags.map((flag) => `'${flag}'`).join(", ")}],
46
+ },` : "// policy: { flags: [] },"}
47
+ };
48
+ `;
49
+ }
50
+ function formatStep(step) {
51
+ const lines = [
52
+ ` {`,
53
+ ` id: '${step.id}',`,
54
+ ` type: '${step.type}',`,
55
+ ` label: '${escapeString(step.label)}',`
56
+ ];
57
+ if (step.description) lines.push(` description: '${escapeString(step.description)}',`);
58
+ const actionLines = [];
59
+ if (step.operation) actionLines.push(`operation: { name: '${step.operation.name}', version: ${step.operation.version} }`);
60
+ if (step.form) actionLines.push(`form: { key: '${step.form.key}', version: ${step.form.version} }`);
61
+ if (actionLines.length) lines.push(` action: { ${actionLines.join(", ")} },`);
62
+ lines.push(` }`);
63
+ return lines.join("\n");
64
+ }
65
+
66
+ //#endregion
67
+ export { generateWorkflowSpec };
@@ -0,0 +1,20 @@
1
+ //#region ../../modules/contractspec-workspace/dist/types/generation-types.js
2
+ /**
3
+ * Default workspace configuration.
4
+ */
5
+ const DEFAULT_WORKSPACE_CONFIG = {
6
+ aiProvider: "claude",
7
+ agentMode: "simple",
8
+ outputDir: "./src",
9
+ conventions: {
10
+ operations: "interactions/commands|queries",
11
+ events: "events",
12
+ presentations: "presentations",
13
+ forms: "forms"
14
+ },
15
+ defaultOwners: [],
16
+ defaultTags: []
17
+ };
18
+
19
+ //#endregion
20
+ export { DEFAULT_WORKSPACE_CONFIG };
@@ -1,3 +1,144 @@
1
- import{AGENT_SYSTEM_PROMPTS as e}from"@lssm/lib.contracts/llm";var t=class{agentType=`claude-code`;formatPlan(t){let n=[];if(n.push(`# Implement: ${t.target.name}.v${t.target.version}`),n.push(``),n.push(`## Context`),n.push(``),n.push(`**Goal:** ${t.context.goal}`),n.push(``),n.push(`**Description:** ${t.context.description}`),n.push(``),t.context.background&&(n.push(`**Background:**`),n.push(t.context.background),n.push(``)),n.push(`## Specification`),n.push(``),n.push(t.specMarkdown),n.push(``),t.fileStructure.length>0){n.push(`## Files to Create/Modify`),n.push(``);for(let e of t.fileStructure){let t=e.type===`create`?`📝`:`✏️`;n.push(`${t} \`${e.path}\``),n.push(` ${e.purpose}`),n.push(``)}}n.push(`## Implementation Steps`),n.push(``);for(let e of t.steps){n.push(`### ${e.order}. ${e.title}`),n.push(``),n.push(e.description),n.push(``),n.push(`**Acceptance Criteria:**`);for(let t of e.acceptanceCriteria)n.push(`- [ ] ${t}`);n.push(``)}if(t.constraints.policy.length>0||t.constraints.security.length>0||t.constraints.pii.length>0){if(n.push(`## Constraints`),n.push(``),t.constraints.policy.length>0){n.push(`### Policy`);for(let e of t.constraints.policy)n.push(`- ${e}`);n.push(``)}if(t.constraints.security.length>0){n.push(`### Security`);for(let e of t.constraints.security)n.push(`- ⚠️ ${e}`);n.push(``)}if(t.constraints.pii.length>0){n.push(`### PII Handling`),n.push(`The following fields contain personally identifiable information:`);for(let e of t.constraints.pii)n.push(`- \`${e}\``);n.push(``)}}n.push(`## Verification Checklist`),n.push(``),n.push(`Before submitting, verify:`);for(let e of t.verificationChecklist)n.push(`- [ ] ${e}`);return n.push(``),n.push(`## Instructions`),n.push(``),n.push(`1. Implement each step in order`),n.push("2. Use TypeScript with strict typing (no `any`)"),n.push(`3. Include JSDoc comments for public APIs`),n.push(`4. Handle all error cases defined in the spec`),n.push(`5. Emit events as specified`),n.push(`6. Mark checklist items as you complete them`),n.push(``),{agent:`claude-code`,systemPrompt:e[`claude-code`],taskPrompt:n.join(`
2
- `)}}generateConfig(e){let t=[];return t.push(`# ContractSpec Implementation Context`),t.push(``),t.push(`This codebase uses ContractSpec for spec-first development.`),t.push(``),t.push(`## Spec Details`),t.push(``),t.push(`- **Name:** ${e.meta.name}`),t.push(`- **Version:** ${e.meta.version}`),t.push(`- **Kind:** ${e.meta.kind}`),t.push(`- **Stability:** ${e.meta.stability}`),t.push(``),t.push(`## Implementation Requirements`),t.push(``),t.push(`1. Match input/output types exactly`),t.push(`2. Handle all defined error cases`),t.push(`3. Emit events as specified`),t.push(`4. Respect policy constraints`),t.push(``),t.join(`
3
- `)}parseOutput(e){let t=e.match(/```(?:typescript|ts|tsx)?\n([\s\S]*?)\n```/);if(t?.[1])return{code:t[1]};let n=[];for(let t of[/error:\s*(.+)/gi,/failed:\s*(.+)/gi,/cannot\s+(.+)/gi]){let r=e.matchAll(t);for(let e of r)e[1]&&n.push(e[1])}return n.length>0?{errors:n}:{code:e}}};const n=new t;export{t as ClaudeCodeAdapter,n as claudeCodeAdapter};
1
+ import { AGENT_SYSTEM_PROMPTS } from "../../../libs/contracts/dist/llm/prompts.js";
2
+ import "../../../libs/contracts/dist/llm/index.js";
3
+
4
+ //#region src/services/agent-guide/adapters/claude-code.ts
5
+ /**
6
+ * Claude Code adapter implementation.
7
+ * Optimized for Claude's extended thinking and code generation capabilities.
8
+ */
9
+ var ClaudeCodeAdapter = class {
10
+ agentType = "claude-code";
11
+ /**
12
+ * Format an implementation plan for Claude Code.
13
+ * Uses structured markdown with clear sections and checklists.
14
+ */
15
+ formatPlan(plan) {
16
+ const lines = [];
17
+ lines.push(`# Implement: ${plan.target.name}.v${plan.target.version}`);
18
+ lines.push("");
19
+ lines.push("## Context");
20
+ lines.push("");
21
+ lines.push(`**Goal:** ${plan.context.goal}`);
22
+ lines.push("");
23
+ lines.push(`**Description:** ${plan.context.description}`);
24
+ lines.push("");
25
+ if (plan.context.background) {
26
+ lines.push(`**Background:**`);
27
+ lines.push(plan.context.background);
28
+ lines.push("");
29
+ }
30
+ lines.push("## Specification");
31
+ lines.push("");
32
+ lines.push(plan.specMarkdown);
33
+ lines.push("");
34
+ if (plan.fileStructure.length > 0) {
35
+ lines.push("## Files to Create/Modify");
36
+ lines.push("");
37
+ for (const file of plan.fileStructure) {
38
+ const icon = file.type === "create" ? "📝" : "✏️";
39
+ lines.push(`${icon} \`${file.path}\``);
40
+ lines.push(` ${file.purpose}`);
41
+ lines.push("");
42
+ }
43
+ }
44
+ lines.push("## Implementation Steps");
45
+ lines.push("");
46
+ for (const step of plan.steps) {
47
+ lines.push(`### ${step.order}. ${step.title}`);
48
+ lines.push("");
49
+ lines.push(step.description);
50
+ lines.push("");
51
+ lines.push("**Acceptance Criteria:**");
52
+ for (const criteria of step.acceptanceCriteria) lines.push(`- [ ] ${criteria}`);
53
+ lines.push("");
54
+ }
55
+ if (plan.constraints.policy.length > 0 || plan.constraints.security.length > 0 || plan.constraints.pii.length > 0) {
56
+ lines.push("## Constraints");
57
+ lines.push("");
58
+ if (plan.constraints.policy.length > 0) {
59
+ lines.push("### Policy");
60
+ for (const p of plan.constraints.policy) lines.push(`- ${p}`);
61
+ lines.push("");
62
+ }
63
+ if (plan.constraints.security.length > 0) {
64
+ lines.push("### Security");
65
+ for (const s of plan.constraints.security) lines.push(`- ⚠️ ${s}`);
66
+ lines.push("");
67
+ }
68
+ if (plan.constraints.pii.length > 0) {
69
+ lines.push("### PII Handling");
70
+ lines.push("The following fields contain personally identifiable information:");
71
+ for (const pii of plan.constraints.pii) lines.push(`- \`${pii}\``);
72
+ lines.push("");
73
+ }
74
+ }
75
+ lines.push("## Verification Checklist");
76
+ lines.push("");
77
+ lines.push("Before submitting, verify:");
78
+ for (const check of plan.verificationChecklist) lines.push(`- [ ] ${check}`);
79
+ lines.push("");
80
+ lines.push("## Instructions");
81
+ lines.push("");
82
+ lines.push("1. Implement each step in order");
83
+ lines.push("2. Use TypeScript with strict typing (no `any`)");
84
+ lines.push("3. Include JSDoc comments for public APIs");
85
+ lines.push("4. Handle all error cases defined in the spec");
86
+ lines.push("5. Emit events as specified");
87
+ lines.push("6. Mark checklist items as you complete them");
88
+ lines.push("");
89
+ return {
90
+ agent: "claude-code",
91
+ systemPrompt: AGENT_SYSTEM_PROMPTS["claude-code"],
92
+ taskPrompt: lines.join("\n")
93
+ };
94
+ }
95
+ /**
96
+ * Generate agent-specific configuration.
97
+ * For Claude Code, this generates a prompt that can be used as context.
98
+ */
99
+ generateConfig(spec) {
100
+ const lines = [];
101
+ lines.push("# ContractSpec Implementation Context");
102
+ lines.push("");
103
+ lines.push("This codebase uses ContractSpec for spec-first development.");
104
+ lines.push("");
105
+ lines.push("## Spec Details");
106
+ lines.push("");
107
+ lines.push(`- **Name:** ${spec.meta.name}`);
108
+ lines.push(`- **Version:** ${spec.meta.version}`);
109
+ lines.push(`- **Kind:** ${spec.meta.kind}`);
110
+ lines.push(`- **Stability:** ${spec.meta.stability}`);
111
+ lines.push("");
112
+ lines.push("## Implementation Requirements");
113
+ lines.push("");
114
+ lines.push("1. Match input/output types exactly");
115
+ lines.push("2. Handle all defined error cases");
116
+ lines.push("3. Emit events as specified");
117
+ lines.push("4. Respect policy constraints");
118
+ lines.push("");
119
+ return lines.join("\n");
120
+ }
121
+ /**
122
+ * Parse Claude Code output to extract generated code.
123
+ */
124
+ parseOutput(output) {
125
+ const codeBlockMatch = output.match(/```(?:typescript|ts|tsx)?\n([\s\S]*?)\n```/);
126
+ if (codeBlockMatch?.[1]) return { code: codeBlockMatch[1] };
127
+ const errors = [];
128
+ for (const pattern of [
129
+ /error:\s*(.+)/gi,
130
+ /failed:\s*(.+)/gi,
131
+ /cannot\s+(.+)/gi
132
+ ]) {
133
+ const matches = output.matchAll(pattern);
134
+ for (const match of matches) if (match[1]) errors.push(match[1]);
135
+ }
136
+ if (errors.length > 0) return { errors };
137
+ return { code: output };
138
+ }
139
+ };
140
+ /** Singleton instance */
141
+ const claudeCodeAdapter = new ClaudeCodeAdapter();
142
+
143
+ //#endregion
144
+ export { ClaudeCodeAdapter, claudeCodeAdapter };
@@ -1,3 +1,135 @@
1
- import{AGENT_SYSTEM_PROMPTS as e,specToFullMarkdown as t}from"@lssm/lib.contracts/llm";var n=class{agentType=`cursor-cli`;formatPlan(t){let n=[];if(n.push(`# ${t.target.name}.v${t.target.version}`),n.push(``),n.push(`> ${t.context.goal}`),n.push(``),t.fileStructure.length>0){n.push(`## Files`),n.push(``);for(let e of t.fileStructure)n.push(`- ${e.type}: \`${e.path}\` - ${e.purpose}`);n.push(``)}n.push(`## Spec`),n.push(``),n.push(t.specMarkdown),n.push(``),n.push(`## Steps`),n.push(``);for(let e of t.steps)n.push(`${e.order}. **${e.title}**: ${e.description}`);n.push(``);let r=[...t.constraints.policy,...t.constraints.security.map(e=>`⚠️ ${e}`)];if(r.length>0){n.push(`## Constraints`),n.push(``);for(let e of r)n.push(`- ${e}`);n.push(``)}return t.constraints.pii.length>0&&(n.push(`## PII Fields`),n.push(``),n.push(`Handle carefully: ${t.constraints.pii.map(e=>`\`${e}\``).join(`, `)}`),n.push(``)),{agent:`cursor-cli`,systemPrompt:e[`cursor-cli`],taskPrompt:n.join(`
2
- `)}}generateConfig(e){let t=e.meta,n=[];if(n.push(`---`),n.push(`description: Implementation rules for ${t.name}.v${t.version}`),n.push(`globs: ["**/${t.name.replace(/\./g,`/`)}/**"]`),n.push(`alwaysApply: false`),n.push(`---`),n.push(``),n.push(`# ${t.name} Implementation Rules`),n.push(``),n.push(`This ${t.kind} operation must follow the ContractSpec specification.`),n.push(``),n.push(`## Goal`),n.push(``),n.push(t.goal),n.push(``),n.push(`## Requirements`),n.push(``),n.push(`1. Input/output types MUST match the spec schema exactly`),n.push(`2. All error cases MUST be handled`),e.sideEffects?.emits?.length&&n.push(`3. Events MUST be emitted as specified`),n.push(`4. Auth level: ${e.policy.auth}`),e.policy.idempotent!==void 0&&n.push(`5. Idempotency: ${e.policy.idempotent}`),n.push(``),e.io.errors&&Object.keys(e.io.errors).length>0){n.push(`## Error Cases`),n.push(``);for(let[t,r]of Object.entries(e.io.errors))n.push(`- \`${t}\` (HTTP ${r.http??400}): ${r.when}`);n.push(``)}if(e.sideEffects?.emits?.length){n.push(`## Events to Emit`),n.push(``);for(let t of e.sideEffects.emits)`ref`in t?n.push(`- \`${t.ref.name}.v${t.ref.version}\`: ${t.when}`):n.push(`- \`${t.name}.v${t.version}\`: ${t.when}`);n.push(``)}if(e.policy.pii?.length){n.push(`## PII Handling`),n.push(``),n.push(`These fields contain PII and must be handled with care:`);for(let t of e.policy.pii)n.push(`- \`${t}\``);n.push(``)}if(e.acceptance?.scenarios?.length){n.push(`## Acceptance Scenarios`),n.push(``);for(let t of e.acceptance.scenarios)n.push(`### ${t.name}`),n.push(`- Given: ${t.given.join(`; `)}`),n.push(`- When: ${t.when.join(`; `)}`),n.push(`- Then: ${t.then.join(`; `)}`),n.push(``)}return n.join(`
3
- `)}getCursorRulesPath(e){return`.cursor/rules/${e.meta.name.replace(/\./g,`-`)}.mdc`}parseOutput(e){let t=e.match(/```(?:typescript|ts|tsx|javascript|js)?\n([\s\S]*?)\n```/);return t?.[1]?{code:t[1]}:{code:e}}};const r=new n;export{n as CursorCLIAdapter,r as cursorCLIAdapter};
1
+ import { AGENT_SYSTEM_PROMPTS } from "../../../libs/contracts/dist/llm/prompts.js";
2
+ import "../../../libs/contracts/dist/llm/index.js";
3
+
4
+ //#region src/services/agent-guide/adapters/cursor-cli.ts
5
+ /**
6
+ * Cursor CLI adapter implementation.
7
+ * Optimized for Cursor's background/composer mode.
8
+ */
9
+ var CursorCLIAdapter = class {
10
+ agentType = "cursor-cli";
11
+ /**
12
+ * Format an implementation plan for Cursor CLI.
13
+ * Uses concise format optimized for Cursor's context window.
14
+ */
15
+ formatPlan(plan) {
16
+ const lines = [];
17
+ lines.push(`# ${plan.target.name}.v${plan.target.version}`);
18
+ lines.push("");
19
+ lines.push(`> ${plan.context.goal}`);
20
+ lines.push("");
21
+ if (plan.fileStructure.length > 0) {
22
+ lines.push("## Files");
23
+ lines.push("");
24
+ for (const file of plan.fileStructure) lines.push(`- ${file.type}: \`${file.path}\` - ${file.purpose}`);
25
+ lines.push("");
26
+ }
27
+ lines.push("## Spec");
28
+ lines.push("");
29
+ lines.push(plan.specMarkdown);
30
+ lines.push("");
31
+ lines.push("## Steps");
32
+ lines.push("");
33
+ for (const step of plan.steps) lines.push(`${step.order}. **${step.title}**: ${step.description}`);
34
+ lines.push("");
35
+ const constraints = [...plan.constraints.policy, ...plan.constraints.security.map((s) => `⚠️ ${s}`)];
36
+ if (constraints.length > 0) {
37
+ lines.push("## Constraints");
38
+ lines.push("");
39
+ for (const c of constraints) lines.push(`- ${c}`);
40
+ lines.push("");
41
+ }
42
+ if (plan.constraints.pii.length > 0) {
43
+ lines.push("## PII Fields");
44
+ lines.push("");
45
+ lines.push(`Handle carefully: ${plan.constraints.pii.map((p) => `\`${p}\``).join(", ")}`);
46
+ lines.push("");
47
+ }
48
+ return {
49
+ agent: "cursor-cli",
50
+ systemPrompt: AGENT_SYSTEM_PROMPTS["cursor-cli"],
51
+ taskPrompt: lines.join("\n")
52
+ };
53
+ }
54
+ /**
55
+ * Generate Cursor rules (.mdc format) for a spec.
56
+ * Can be saved to .cursor/rules/ to provide persistent context.
57
+ */
58
+ generateConfig(spec) {
59
+ const m = spec.meta;
60
+ const lines = [];
61
+ lines.push("---");
62
+ lines.push(`description: Implementation rules for ${m.name}.v${m.version}`);
63
+ lines.push(`globs: ["**/${m.name.replace(/\./g, "/")}/**"]`);
64
+ lines.push("alwaysApply: false");
65
+ lines.push("---");
66
+ lines.push("");
67
+ lines.push(`# ${m.name} Implementation Rules`);
68
+ lines.push("");
69
+ lines.push(`This ${m.kind} operation must follow the ContractSpec specification.`);
70
+ lines.push("");
71
+ lines.push("## Goal");
72
+ lines.push("");
73
+ lines.push(m.goal);
74
+ lines.push("");
75
+ lines.push("## Requirements");
76
+ lines.push("");
77
+ lines.push("1. Input/output types MUST match the spec schema exactly");
78
+ lines.push("2. All error cases MUST be handled");
79
+ if (spec.sideEffects?.emits?.length) lines.push("3. Events MUST be emitted as specified");
80
+ lines.push(`4. Auth level: ${spec.policy.auth}`);
81
+ if (spec.policy.idempotent !== void 0) lines.push(`5. Idempotency: ${spec.policy.idempotent}`);
82
+ lines.push("");
83
+ if (spec.io.errors && Object.keys(spec.io.errors).length > 0) {
84
+ lines.push("## Error Cases");
85
+ lines.push("");
86
+ for (const [code, err] of Object.entries(spec.io.errors)) lines.push(`- \`${code}\` (HTTP ${err.http ?? 400}): ${err.when}`);
87
+ lines.push("");
88
+ }
89
+ if (spec.sideEffects?.emits?.length) {
90
+ lines.push("## Events to Emit");
91
+ lines.push("");
92
+ for (const e of spec.sideEffects.emits) if ("ref" in e) lines.push(`- \`${e.ref.name}.v${e.ref.version}\`: ${e.when}`);
93
+ else lines.push(`- \`${e.name}.v${e.version}\`: ${e.when}`);
94
+ lines.push("");
95
+ }
96
+ if (spec.policy.pii?.length) {
97
+ lines.push("## PII Handling");
98
+ lines.push("");
99
+ lines.push("These fields contain PII and must be handled with care:");
100
+ for (const field of spec.policy.pii) lines.push(`- \`${field}\``);
101
+ lines.push("");
102
+ }
103
+ if (spec.acceptance?.scenarios?.length) {
104
+ lines.push("## Acceptance Scenarios");
105
+ lines.push("");
106
+ for (const s of spec.acceptance.scenarios) {
107
+ lines.push(`### ${s.name}`);
108
+ lines.push(`- Given: ${s.given.join("; ")}`);
109
+ lines.push(`- When: ${s.when.join("; ")}`);
110
+ lines.push(`- Then: ${s.then.join("; ")}`);
111
+ lines.push("");
112
+ }
113
+ }
114
+ return lines.join("\n");
115
+ }
116
+ /**
117
+ * Generate a cursor rules file path for a spec.
118
+ */
119
+ getCursorRulesPath(spec) {
120
+ return `.cursor/rules/${spec.meta.name.replace(/\./g, "-")}.mdc`;
121
+ }
122
+ /**
123
+ * Parse Cursor output to extract generated code.
124
+ */
125
+ parseOutput(output) {
126
+ const codeBlockMatch = output.match(/```(?:typescript|ts|tsx|javascript|js)?\n([\s\S]*?)\n```/);
127
+ if (codeBlockMatch?.[1]) return { code: codeBlockMatch[1] };
128
+ return { code: output };
129
+ }
130
+ };
131
+ /** Singleton instance */
132
+ const cursorCLIAdapter = new CursorCLIAdapter();
133
+
134
+ //#endregion
135
+ export { CursorCLIAdapter, cursorCLIAdapter };