@lssm/module.contractspec-workspace 0.0.0-canary-20251217080011 → 1.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/ai/code-generation.js +13 -50
  2. package/dist/ai/spec-creation.js +18 -50
  3. package/dist/analysis/deps/graph.js +2 -84
  4. package/dist/analysis/deps/parse-imports.js +1 -30
  5. package/dist/analysis/diff/semantic.js +1 -96
  6. package/dist/analysis/feature-scan.js +1 -151
  7. package/dist/analysis/spec-scan.js +1 -344
  8. package/dist/analysis/validate/spec-structure.js +1 -122
  9. package/dist/index.js +1 -25
  10. package/dist/templates/app-config.js +28 -100
  11. package/dist/templates/data-view.js +27 -41
  12. package/dist/templates/event.js +14 -28
  13. package/dist/templates/experiment.js +51 -76
  14. package/dist/templates/handler.js +17 -49
  15. package/dist/templates/integration-utils.js +26 -97
  16. package/dist/templates/integration.js +23 -46
  17. package/dist/templates/knowledge.js +19 -59
  18. package/dist/templates/migration.js +26 -49
  19. package/dist/templates/operation.js +28 -40
  20. package/dist/templates/presentation.js +20 -45
  21. package/dist/templates/telemetry.js +53 -73
  22. package/dist/templates/utils.js +1 -38
  23. package/dist/templates/workflow-runner.js +6 -12
  24. package/dist/templates/workflow.js +24 -50
  25. package/dist/types/generation-types.js +1 -20
  26. package/package.json +6 -7
  27. package/dist/ai/code-generation.d.ts +0 -27
  28. package/dist/ai/spec-creation.d.ts +0 -26
  29. package/dist/analysis/deps/graph.d.ts +0 -33
  30. package/dist/analysis/deps/parse-imports.d.ts +0 -16
  31. package/dist/analysis/diff/semantic.d.ts +0 -10
  32. package/dist/analysis/feature-scan.d.ts +0 -14
  33. package/dist/analysis/spec-scan.d.ts +0 -33
  34. package/dist/analysis/validate/spec-structure.d.ts +0 -10
  35. package/dist/index.d.ts +0 -26
  36. package/dist/templates/app-config.d.ts +0 -6
  37. package/dist/templates/data-view.d.ts +0 -6
  38. package/dist/templates/event.d.ts +0 -10
  39. package/dist/templates/experiment.d.ts +0 -6
  40. package/dist/templates/handler.d.ts +0 -19
  41. package/dist/templates/integration.d.ts +0 -6
  42. package/dist/templates/knowledge.d.ts +0 -6
  43. package/dist/templates/migration.d.ts +0 -6
  44. package/dist/templates/operation.d.ts +0 -10
  45. package/dist/templates/presentation.d.ts +0 -10
  46. package/dist/templates/telemetry.d.ts +0 -6
  47. package/dist/templates/utils.d.ts +0 -26
  48. package/dist/templates/workflow-runner.d.ts +0 -15
  49. package/dist/templates/workflow.d.ts +0 -10
  50. package/dist/types/analysis-types.d.ts +0 -125
  51. package/dist/types/generation-types.d.ts +0 -83
  52. package/dist/types/spec-types.d.ts +0 -344
@@ -1,344 +1 @@
1
- //#region src/analysis/spec-scan.ts
2
- /**
3
- * Infer spec type from file path based on naming conventions.
4
- * Supports all contract types from @lssm/lib.contracts.
5
- */
6
- function inferSpecTypeFromFilePath(filePath) {
7
- if (filePath.includes(".contracts.") || filePath.includes("/contracts/")) return "operation";
8
- if (filePath.includes(".event.") || filePath.includes("/events/") || filePath.endsWith("/events.ts")) return "event";
9
- if (filePath.includes(".presentation.") || filePath.includes("/presentations/") || filePath.endsWith("/presentations.ts")) return "presentation";
10
- if (filePath.includes(".feature.")) return "feature";
11
- if (filePath.includes(".capability.")) return "capability";
12
- if (filePath.includes(".data-view.")) return "data-view";
13
- if (filePath.includes(".form.")) return "form";
14
- if (filePath.includes(".migration.")) return "migration";
15
- if (filePath.includes(".workflow.")) return "workflow";
16
- if (filePath.includes(".experiment.")) return "experiment";
17
- if (filePath.includes(".integration.")) return "integration";
18
- if (filePath.includes(".knowledge.")) return "knowledge";
19
- if (filePath.includes(".telemetry.")) return "telemetry";
20
- if (filePath.includes(".app-config.")) return "app-config";
21
- if (filePath.includes(".policy.")) return "policy";
22
- if (filePath.includes(".test-spec.")) return "test-spec";
23
- return "unknown";
24
- }
25
- /**
26
- * Scan spec source code to extract metadata without executing it.
27
- */
28
- function scanSpecSource(code, filePath) {
29
- const specType = inferSpecTypeFromFilePath(filePath);
30
- const name = matchStringField(code, "name");
31
- const description = matchStringField(code, "description");
32
- const stabilityRaw = matchStringField(code, "stability");
33
- const stability = isStability(stabilityRaw) ? stabilityRaw : void 0;
34
- const owners = matchStringArrayField(code, "owners");
35
- const tags = matchStringArrayField(code, "tags");
36
- const version = matchNumberField(code, "version");
37
- const kind = inferOperationKind(code);
38
- const hasMeta = /meta\s*:\s*{/.test(code);
39
- const hasIo = /\bio\s*:\s*{/.test(code);
40
- const hasPolicy = /\bpolicy\s*:\s*{/.test(code);
41
- const hasPayload = /\bpayload\s*:\s*{/.test(code);
42
- const hasContent = /\bcontent\s*:\s*{/.test(code);
43
- const hasDefinition = /\bdefinition\s*:\s*{/.test(code);
44
- const emittedEvents = specType === "operation" ? extractEmittedEvents(code) : void 0;
45
- const policyRefs = specType === "operation" ? extractPolicyRefs(code) : void 0;
46
- const testRefs = extractTestRefs(code);
47
- return {
48
- filePath,
49
- specType,
50
- name: name ?? void 0,
51
- description: description ?? void 0,
52
- stability,
53
- owners,
54
- tags,
55
- version: version ?? void 0,
56
- kind,
57
- hasMeta,
58
- hasIo,
59
- hasPolicy,
60
- hasPayload,
61
- hasContent,
62
- hasDefinition,
63
- emittedEvents,
64
- policyRefs,
65
- testRefs
66
- };
67
- }
68
- /**
69
- * Extract emitted event refs from operation spec source.
70
- * Looks for sideEffects.emits array entries.
71
- */
72
- function extractEmittedEvents(code) {
73
- const events = [];
74
- const inlinePattern = /\{\s*name:\s*['"]([^'"]+)['"]\s*,\s*version:\s*(\d+)/g;
75
- let match;
76
- while ((match = inlinePattern.exec(code)) !== null) if (match[1] && match[2]) events.push({
77
- name: match[1],
78
- version: Number(match[2])
79
- });
80
- const refPattern = /\{\s*ref:\s*(\w+)/g;
81
- while ((match = refPattern.exec(code)) !== null) if (match[1] && !match[1].startsWith("when")) {}
82
- return events.length > 0 ? events : void 0;
83
- }
84
- /**
85
- * Extract policy refs from operation spec source.
86
- */
87
- function extractPolicyRefs(code) {
88
- const policies = [];
89
- const policyPattern = /\{\s*name:\s*['"]([^'"]+)['"]\s*,\s*version:\s*(\d+)/g;
90
- const policySectionMatch = code.match(/policies\s*:\s*\[([\s\S]*?)\]/);
91
- if (policySectionMatch?.[1]) {
92
- let match;
93
- while ((match = policyPattern.exec(policySectionMatch[1])) !== null) if (match[1] && match[2]) policies.push({
94
- name: match[1],
95
- version: Number(match[2])
96
- });
97
- }
98
- return policies.length > 0 ? policies : void 0;
99
- }
100
- /**
101
- * Extract test spec refs.
102
- */
103
- function extractTestRefs(code) {
104
- const tests = [];
105
- const testsSectionMatch = code.match(/tests\s*:\s*\[([\s\S]*?)\]/);
106
- if (testsSectionMatch?.[1]) {
107
- const refPattern = /\{\s*name:\s*['"]([^'"]+)['"]\s*,\s*version:\s*(\d+)/g;
108
- let match;
109
- while ((match = refPattern.exec(testsSectionMatch[1])) !== null) if (match[1] && match[2]) tests.push({
110
- name: match[1],
111
- version: Number(match[2])
112
- });
113
- }
114
- return tests.length > 0 ? tests : void 0;
115
- }
116
- function matchStringField(code, field) {
117
- const regex = /* @__PURE__ */ new RegExp(`${escapeRegex(field)}\\s*:\\s*['"]([^'"]+)['"]`);
118
- return code.match(regex)?.[1] ?? null;
119
- }
120
- function matchNumberField(code, field) {
121
- const regex = /* @__PURE__ */ new RegExp(`${escapeRegex(field)}\\s*:\\s*(\\d+)`);
122
- const match = code.match(regex);
123
- if (!match?.[1]) return null;
124
- const parsed = Number(match[1]);
125
- return Number.isFinite(parsed) ? parsed : null;
126
- }
127
- function matchStringArrayField(code, field) {
128
- const regex = /* @__PURE__ */ new RegExp(`${escapeRegex(field)}\\s*:\\s*\\[([\\s\\S]*?)\\]`);
129
- const match = code.match(regex);
130
- if (!match?.[1]) return void 0;
131
- const inner = match[1];
132
- const items = Array.from(inner.matchAll(/['"]([^'"]+)['"]/g)).map((m) => m[1]).filter((value) => typeof value === "string" && value.length > 0);
133
- return items.length > 0 ? items : void 0;
134
- }
135
- function isStability(value) {
136
- return value === "experimental" || value === "beta" || value === "stable" || value === "deprecated";
137
- }
138
- function escapeRegex(value) {
139
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
140
- }
141
- /**
142
- * Infer operation kind from source code.
143
- * First checks for defineCommand/defineQuery usage (which set kind automatically),
144
- * then falls back to explicit kind field.
145
- */
146
- function inferOperationKind(code) {
147
- if (/defineCommand\s*\(/.test(code)) return "command";
148
- if (/defineQuery\s*\(/.test(code)) return "query";
149
- const kindRaw = matchStringField(code, "kind");
150
- return kindRaw === "command" || kindRaw === "query" ? kindRaw : "unknown";
151
- }
152
- /**
153
- * Infer operation kind from a specific code block.
154
- */
155
- function inferOperationKindFromBlock(block) {
156
- if (/defineCommand\s*\(/.test(block)) return "command";
157
- if (/defineQuery\s*\(/.test(block)) return "query";
158
- const kindRaw = matchStringField(block, "kind");
159
- return kindRaw === "command" || kindRaw === "query" ? kindRaw : "unknown";
160
- }
161
- /**
162
- * Extract name and version from a meta block.
163
- */
164
- function extractMetaFromBlock(block) {
165
- const name = matchStringField(block, "name");
166
- const version = matchNumberField(block, "version");
167
- if (name && version !== null) return {
168
- name,
169
- version
170
- };
171
- return null;
172
- }
173
- /**
174
- * Define function patterns for all spec types.
175
- */
176
- const DEFINE_FUNCTION_PATTERNS = [
177
- {
178
- pattern: /defineCommand\s*\(\s*\{/g,
179
- type: "operation"
180
- },
181
- {
182
- pattern: /defineQuery\s*\(\s*\{/g,
183
- type: "operation"
184
- },
185
- {
186
- pattern: /defineEvent\s*\(\s*\{/g,
187
- type: "event"
188
- },
189
- {
190
- pattern: /:\s*PresentationDescriptorV2\s*=\s*\{/g,
191
- type: "presentation"
192
- },
193
- {
194
- pattern: /:\s*PresentationDescriptor\s*=\s*\{/g,
195
- type: "presentation"
196
- },
197
- {
198
- pattern: /definePresentation\s*\(\s*\{/g,
199
- type: "presentation"
200
- },
201
- {
202
- pattern: /defineCapability\s*\(\s*\{/g,
203
- type: "capability"
204
- },
205
- {
206
- pattern: /defineWorkflow\s*\(\s*\{/g,
207
- type: "workflow"
208
- },
209
- {
210
- pattern: /defineExperiment\s*\(\s*\{/g,
211
- type: "experiment"
212
- },
213
- {
214
- pattern: /defineIntegration\s*\(\s*\{/g,
215
- type: "integration"
216
- },
217
- {
218
- pattern: /defineKnowledge\s*\(\s*\{/g,
219
- type: "knowledge"
220
- },
221
- {
222
- pattern: /defineTelemetry\s*\(\s*\{/g,
223
- type: "telemetry"
224
- },
225
- {
226
- pattern: /defineAppConfig\s*\(\s*\{/g,
227
- type: "app-config"
228
- },
229
- {
230
- pattern: /definePolicy\s*\(\s*\{/g,
231
- type: "policy"
232
- },
233
- {
234
- pattern: /defineTestSpec\s*\(\s*\{/g,
235
- type: "test-spec"
236
- },
237
- {
238
- pattern: /defineDataView\s*\(\s*\{/g,
239
- type: "data-view"
240
- },
241
- {
242
- pattern: /defineForm\s*\(\s*\{/g,
243
- type: "form"
244
- },
245
- {
246
- pattern: /defineMigration\s*\(\s*\{/g,
247
- type: "migration"
248
- }
249
- ];
250
- /**
251
- * Find matching closing brace for an opening brace.
252
- * Returns the index of the closing brace or -1 if not found.
253
- */
254
- function findMatchingBrace(code, startIndex) {
255
- let depth = 0;
256
- let inString = false;
257
- let stringChar = "";
258
- for (let i = startIndex; i < code.length; i++) {
259
- const char = code[i];
260
- const prevChar = i > 0 ? code[i - 1] : "";
261
- if ((char === "\"" || char === "'" || char === "`") && prevChar !== "\\") {
262
- if (!inString) {
263
- inString = true;
264
- stringChar = char;
265
- } else if (char === stringChar) inString = false;
266
- continue;
267
- }
268
- if (inString) continue;
269
- if (char === "{") depth++;
270
- else if (char === "}") {
271
- depth--;
272
- if (depth === 0) return i;
273
- }
274
- }
275
- return -1;
276
- }
277
- /**
278
- * Scan spec source code to extract ALL specs from a file.
279
- * This function finds multiple spec definitions in a single file.
280
- */
281
- function scanAllSpecsFromSource(code, filePath) {
282
- const results = [];
283
- const baseSpecType = inferSpecTypeFromFilePath(filePath);
284
- const processedPositions = /* @__PURE__ */ new Set();
285
- for (const { pattern, type } of DEFINE_FUNCTION_PATTERNS) {
286
- pattern.lastIndex = 0;
287
- let match;
288
- while ((match = pattern.exec(code)) !== null) {
289
- const startPos = match.index;
290
- if (processedPositions.has(startPos)) continue;
291
- processedPositions.add(startPos);
292
- const openBracePos = code.indexOf("{", startPos);
293
- if (openBracePos === -1) continue;
294
- const closeBracePos = findMatchingBrace(code, openBracePos);
295
- if (closeBracePos === -1) continue;
296
- const block = code.slice(openBracePos, closeBracePos + 1);
297
- const meta = extractMetaFromBlock(block);
298
- if (!meta) continue;
299
- const description = matchStringField(block, "description");
300
- const stabilityRaw = matchStringField(block, "stability");
301
- const stability = isStability(stabilityRaw) ? stabilityRaw : void 0;
302
- const owners = matchStringArrayField(block, "owners");
303
- const tags = matchStringArrayField(block, "tags");
304
- const hasMeta = /meta\s*:\s*{/.test(block);
305
- const hasIo = /\bio\s*:\s*{/.test(block);
306
- const hasPolicy = /\bpolicy\s*:\s*{/.test(block);
307
- const hasPayload = /\bpayload\s*:\s*{/.test(block);
308
- const hasContent = /\bcontent\s*:\s*{/.test(block);
309
- const hasDefinition = /\bdefinition\s*:\s*{/.test(block);
310
- const kind = type === "operation" ? inferOperationKindFromBlock(block) : "unknown";
311
- const emittedEvents = type === "operation" ? extractEmittedEvents(block) : void 0;
312
- const policyRefs = type === "operation" ? extractPolicyRefs(block) : void 0;
313
- const testRefs = extractTestRefs(block);
314
- results.push({
315
- filePath,
316
- specType: type,
317
- name: meta.name,
318
- version: meta.version,
319
- description: description ?? void 0,
320
- stability,
321
- owners,
322
- tags,
323
- kind,
324
- hasMeta,
325
- hasIo,
326
- hasPolicy,
327
- hasPayload,
328
- hasContent,
329
- hasDefinition,
330
- emittedEvents,
331
- policyRefs,
332
- testRefs
333
- });
334
- }
335
- }
336
- if (results.length === 0 && baseSpecType !== "unknown") {
337
- const fallback = scanSpecSource(code, filePath);
338
- if (fallback.name && fallback.version !== void 0) results.push(fallback);
339
- }
340
- return results;
341
- }
342
-
343
- //#endregion
344
- export { extractEmittedEvents, extractPolicyRefs, extractTestRefs, inferSpecTypeFromFilePath, scanAllSpecsFromSource, scanSpecSource };
1
+ function e(e){return e.includes(`.contracts.`)||e.includes(`/contracts/`)?`operation`:e.includes(`.event.`)||e.includes(`/events/`)||e.endsWith(`/events.ts`)?`event`:e.includes(`.presentation.`)||e.includes(`/presentations/`)||e.endsWith(`/presentations.ts`)?`presentation`:e.includes(`.feature.`)?`feature`:e.includes(`.capability.`)?`capability`:e.includes(`.data-view.`)?`data-view`:e.includes(`.form.`)?`form`:e.includes(`.migration.`)?`migration`:e.includes(`.workflow.`)?`workflow`:e.includes(`.experiment.`)?`experiment`:e.includes(`.integration.`)?`integration`:e.includes(`.knowledge.`)?`knowledge`:e.includes(`.telemetry.`)?`telemetry`:e.includes(`.app-config.`)?`app-config`:e.includes(`.policy.`)?`policy`:e.includes(`.test-spec.`)?`test-spec`:`unknown`}function t(t,l){let d=e(l),f=a(t,`name`),p=a(t,`description`),m=a(t,`stability`),h=c(m)?m:void 0,g=s(t,`owners`),_=s(t,`tags`),v=o(t,`version`),y=u(t),b=/meta\s*:\s*{/.test(t),x=/\bio\s*:\s*{/.test(t),S=/\bpolicy\s*:\s*{/.test(t),C=/\bpayload\s*:\s*{/.test(t),w=/\bcontent\s*:\s*{/.test(t),T=/\bdefinition\s*:\s*{/.test(t),E=d===`operation`?n(t):void 0,D=d===`operation`?r(t):void 0,O=i(t);return{filePath:l,specType:d,name:f??void 0,description:p??void 0,stability:h,owners:g,tags:_,version:v??void 0,kind:y,hasMeta:b,hasIo:x,hasPolicy:S,hasPayload:C,hasContent:w,hasDefinition:T,emittedEvents:E,policyRefs:D,testRefs:O}}function n(e){let t=[],n=/\{\s*name:\s*['"]([^'"]+)['"]\s*,\s*version:\s*(\d+)/g,r;for(;(r=n.exec(e))!==null;)r[1]&&r[2]&&t.push({name:r[1],version:Number(r[2])});let i=/\{\s*ref:\s*(\w+)/g;for(;(r=i.exec(e))!==null;)r[1]&&r[1].startsWith(`when`);return t.length>0?t:void 0}function r(e){let t=[],n=/\{\s*name:\s*['"]([^'"]+)['"]\s*,\s*version:\s*(\d+)/g,r=e.match(/policies\s*:\s*\[([\s\S]*?)\]/);if(r?.[1]){let e;for(;(e=n.exec(r[1]))!==null;)e[1]&&e[2]&&t.push({name:e[1],version:Number(e[2])})}return t.length>0?t:void 0}function i(e){let t=[],n=e.match(/tests\s*:\s*\[([\s\S]*?)\]/);if(n?.[1]){let e=/\{\s*name:\s*['"]([^'"]+)['"]\s*,\s*version:\s*(\d+)/g,r;for(;(r=e.exec(n[1]))!==null;)r[1]&&r[2]&&t.push({name:r[1],version:Number(r[2])})}return t.length>0?t:void 0}function a(e,t){let n=RegExp(`${l(t)}\\s*:\\s*['"]([^'"]+)['"]`);return e.match(n)?.[1]??null}function o(e,t){let n=RegExp(`${l(t)}\\s*:\\s*(\\d+)`),r=e.match(n);if(!r?.[1])return null;let i=Number(r[1]);return Number.isFinite(i)?i:null}function s(e,t){let n=RegExp(`${l(t)}\\s*:\\s*\\[([\\s\\S]*?)\\]`),r=e.match(n);if(!r?.[1])return;let i=r[1],a=Array.from(i.matchAll(/['"]([^'"]+)['"]/g)).map(e=>e[1]).filter(e=>typeof e==`string`&&e.length>0);return a.length>0?a:void 0}function c(e){return e===`experimental`||e===`beta`||e===`stable`||e===`deprecated`}function l(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function u(e){if(/defineCommand\s*\(/.test(e))return`command`;if(/defineQuery\s*\(/.test(e))return`query`;let t=a(e,`kind`);return t===`command`||t===`query`?t:`unknown`}function d(e){if(/defineCommand\s*\(/.test(e))return`command`;if(/defineQuery\s*\(/.test(e))return`query`;let t=a(e,`kind`);return t===`command`||t===`query`?t:`unknown`}function f(e){let t=a(e,`name`),n=o(e,`version`);return t&&n!==null?{name:t,version:n}:null}const p=[{pattern:/defineCommand\s*\(\s*\{/g,type:`operation`},{pattern:/defineQuery\s*\(\s*\{/g,type:`operation`},{pattern:/defineEvent\s*\(\s*\{/g,type:`event`},{pattern:/:\s*PresentationDescriptorV2\s*=\s*\{/g,type:`presentation`},{pattern:/:\s*PresentationDescriptor\s*=\s*\{/g,type:`presentation`},{pattern:/definePresentation\s*\(\s*\{/g,type:`presentation`},{pattern:/defineCapability\s*\(\s*\{/g,type:`capability`},{pattern:/defineWorkflow\s*\(\s*\{/g,type:`workflow`},{pattern:/defineExperiment\s*\(\s*\{/g,type:`experiment`},{pattern:/defineIntegration\s*\(\s*\{/g,type:`integration`},{pattern:/defineKnowledge\s*\(\s*\{/g,type:`knowledge`},{pattern:/defineTelemetry\s*\(\s*\{/g,type:`telemetry`},{pattern:/defineAppConfig\s*\(\s*\{/g,type:`app-config`},{pattern:/definePolicy\s*\(\s*\{/g,type:`policy`},{pattern:/defineTestSpec\s*\(\s*\{/g,type:`test-spec`},{pattern:/defineDataView\s*\(\s*\{/g,type:`data-view`},{pattern:/defineForm\s*\(\s*\{/g,type:`form`},{pattern:/defineMigration\s*\(\s*\{/g,type:`migration`}];function m(e,t){let n=0,r=!1,i=``;for(let a=t;a<e.length;a++){let t=e[a],o=a>0?e[a-1]:``;if((t===`"`||t===`'`||t==="`")&&o!==`\\`){r?t===i&&(r=!1):(r=!0,i=t);continue}if(!r){if(t===`{`)n++;else if(t===`}`&&(n--,n===0))return a}}return-1}function h(o,l){let u=[],h=e(l),g=new Set;for(let{pattern:e,type:t}of p){e.lastIndex=0;let p;for(;(p=e.exec(o))!==null;){let e=p.index;if(g.has(e))continue;g.add(e);let h=o.indexOf(`{`,e);if(h===-1)continue;let _=m(o,h);if(_===-1)continue;let v=o.slice(h,_+1),y=f(v);if(!y)continue;let b=a(v,`description`),x=a(v,`stability`),S=c(x)?x:void 0,C=s(v,`owners`),w=s(v,`tags`),T=/meta\s*:\s*{/.test(v),E=/\bio\s*:\s*{/.test(v),D=/\bpolicy\s*:\s*{/.test(v),O=/\bpayload\s*:\s*{/.test(v),k=/\bcontent\s*:\s*{/.test(v),A=/\bdefinition\s*:\s*{/.test(v),j=t===`operation`?d(v):`unknown`,M=t===`operation`?n(v):void 0,N=t===`operation`?r(v):void 0,P=i(v);u.push({filePath:l,specType:t,name:y.name,version:y.version,description:b??void 0,stability:S,owners:C,tags:w,kind:j,hasMeta:T,hasIo:E,hasPolicy:D,hasPayload:O,hasContent:k,hasDefinition:A,emittedEvents:M,policyRefs:N,testRefs:P})}}if(u.length===0&&h!==`unknown`){let e=t(o,l);e.name&&e.version!==void 0&&u.push(e)}return u}export{n as extractEmittedEvents,r as extractPolicyRefs,i as extractTestRefs,e as inferSpecTypeFromFilePath,h as scanAllSpecsFromSource,t as scanSpecSource};
@@ -1,122 +1 @@
1
- //#region src/analysis/validate/spec-structure.ts
2
- /**
3
- * Validate spec structure based on source code and filename.
4
- */
5
- function validateSpecStructure(code, fileName) {
6
- const errors = [];
7
- const warnings = [];
8
- if (!/export\s+(const|let)\s+\w+/.test(code)) errors.push("No exported spec found");
9
- if (fileName.includes(".contracts.")) validateOperationSpec(code, errors, warnings);
10
- if (fileName.includes(".event.")) validateEventSpec(code, errors, warnings);
11
- if (fileName.includes(".presentation.")) validatePresentationSpec(code, errors, warnings);
12
- if (fileName.includes(".workflow.")) validateWorkflowSpec(code, errors, warnings);
13
- if (fileName.includes(".data-view.")) validateDataViewSpec(code, errors, warnings);
14
- if (fileName.includes(".migration.")) validateMigrationSpec(code, errors, warnings);
15
- if (fileName.includes(".telemetry.")) validateTelemetrySpec(code, errors, warnings);
16
- if (fileName.includes(".experiment.")) validateExperimentSpec(code, errors, warnings);
17
- if (fileName.includes(".app-config.")) validateAppConfigSpec(code, errors, warnings);
18
- validateCommonFields(code, errors, warnings);
19
- return {
20
- valid: errors.length === 0,
21
- errors,
22
- warnings
23
- };
24
- }
25
- /**
26
- * Validate operation spec
27
- */
28
- function validateOperationSpec(code, errors, warnings) {
29
- if (!/define(Command|Query)/.test(code)) errors.push("Missing defineCommand or defineQuery call");
30
- if (!code.includes("meta:")) errors.push("Missing meta section");
31
- if (!code.includes("io:")) errors.push("Missing io section");
32
- if (!code.includes("policy:")) errors.push("Missing policy section");
33
- if (!code.match(/name:\s*['"][^'"]+['"]/)) errors.push("Missing or invalid name field");
34
- if (!code.match(/version:\s*\d+/)) errors.push("Missing or invalid version field");
35
- const hasDefineCommand = /defineCommand\s*\(/.test(code);
36
- const hasDefineQuery = /defineQuery\s*\(/.test(code);
37
- const hasExplicitKind = /kind:\s*['"](?:command|query)['"]/.test(code);
38
- if (!hasDefineCommand && !hasDefineQuery && !hasExplicitKind) errors.push("Missing kind: use defineCommand(), defineQuery(), or explicit kind field");
39
- if (!code.includes("acceptance:")) warnings.push("No acceptance scenarios defined");
40
- if (!code.includes("examples:")) warnings.push("No examples provided");
41
- if (code.includes("TODO")) warnings.push("Contains TODO items that need completion");
42
- }
43
- function validateTelemetrySpec(code, errors, warnings) {
44
- if (!code.match(/:\s*TelemetrySpec\s*=/)) errors.push("Missing TelemetrySpec type annotation");
45
- if (!code.match(/meta:\s*{[\s\S]*name:/)) errors.push("TelemetrySpec.meta is required");
46
- if (!code.includes("events:")) errors.push("TelemetrySpec must declare events");
47
- if (!code.match(/privacy:\s*'(public|internal|pii|sensitive)'/)) warnings.push("No explicit privacy classification found");
48
- }
49
- function validateExperimentSpec(code, errors, warnings) {
50
- if (!code.match(/:\s*ExperimentSpec\s*=/)) errors.push("Missing ExperimentSpec type annotation");
51
- if (!code.includes("controlVariant")) errors.push("ExperimentSpec must declare controlVariant");
52
- if (!code.includes("variants:")) errors.push("ExperimentSpec must declare variants");
53
- if (!code.match(/allocation:\s*{/)) warnings.push("ExperimentSpec missing allocation configuration");
54
- }
55
- function validateAppConfigSpec(code, errors, warnings) {
56
- if (!code.match(/:\s*AppBlueprintSpec\s*=/)) errors.push("Missing AppBlueprintSpec type annotation");
57
- if (!code.includes("meta:")) errors.push("AppBlueprintSpec must define meta");
58
- if (!code.includes("appId")) warnings.push("AppBlueprint meta missing appId assignment");
59
- if (!code.includes("capabilities")) warnings.push("App blueprint spec does not declare capabilities");
60
- }
61
- /**
62
- * Validate event spec
63
- */
64
- function validateEventSpec(code, errors, warnings) {
65
- if (!code.includes("defineEvent")) errors.push("Missing defineEvent call");
66
- if (!code.match(/name:\s*['"][^'"]+['"]/)) errors.push("Missing or invalid name field");
67
- if (!code.match(/version:\s*\d+/)) errors.push("Missing or invalid version field");
68
- if (!code.includes("payload:")) errors.push("Missing payload field");
69
- const nameMatch = code.match(/name:\s*['"]([^'"]+)['"]/);
70
- if (nameMatch?.[1]) {
71
- if (!(nameMatch[1].split(".").pop() ?? "").match(/(ed|created|updated|deleted|completed)$/i)) warnings.push("Event name should use past tense (e.g., \"created\", \"updated\")");
72
- }
73
- }
74
- /**
75
- * Validate presentation spec
76
- */
77
- function validatePresentationSpec(code, errors, _warnings) {
78
- if (!code.match(/:\s*PresentationSpec\s*=/)) errors.push("Missing PresentationSpec type annotation");
79
- if (!code.includes("meta:")) errors.push("Missing meta section");
80
- if (!code.includes("content:")) errors.push("Missing content section");
81
- if (!code.match(/kind:\s*['"](?:web_component|markdown|data)['"]/)) errors.push("Missing or invalid kind field");
82
- }
83
- function validateWorkflowSpec(code, errors, warnings) {
84
- if (!code.match(/:\s*WorkflowSpec\s*=/)) errors.push("Missing WorkflowSpec type annotation");
85
- if (!code.includes("definition:")) errors.push("Missing definition section");
86
- if (!code.includes("steps:")) errors.push("Workflow must declare steps");
87
- if (!code.includes("transitions:")) warnings.push("No transitions declared; workflow will complete after first step.");
88
- if (!code.match(/title:\s*['"][^'"]+['"]/)) warnings.push("Missing workflow title");
89
- if (!code.match(/domain:\s*['"][^'"]+['"]/)) warnings.push("Missing domain field");
90
- if (code.includes("TODO")) warnings.push("Contains TODO items that need completion");
91
- }
92
- function validateMigrationSpec(code, errors, warnings) {
93
- if (!code.match(/:\s*MigrationSpec\s*=/)) errors.push("Missing MigrationSpec type annotation");
94
- if (!code.includes("plan:")) errors.push("Missing plan section");
95
- else if (!code.includes("up:")) errors.push("Migration must define at least one up step");
96
- if (!code.match(/name:\s*['"][^'"]+['"]/)) errors.push("Missing or invalid migration name");
97
- if (!code.match(/version:\s*\d+/)) errors.push("Missing or invalid migration version");
98
- if (code.includes("TODO")) warnings.push("Contains TODO items that need completion");
99
- }
100
- /**
101
- * Validate common fields across all spec types
102
- */
103
- function validateCommonFields(code, errors, warnings) {
104
- if (code.includes("SchemaModel") && !code.includes("from '@lssm/lib.schema'")) errors.push("Missing import for SchemaModel from @lssm/lib.schema");
105
- if (!code.includes("from '@lssm/lib.contracts'")) errors.push("Missing import from @lssm/lib.contracts");
106
- const ownersMatch = code.match(/owners:\s*\[(.*?)\]/s);
107
- if (ownersMatch?.[1]) {
108
- if (!ownersMatch[1].includes("@")) warnings.push("Owners should start with @ (e.g., \"@team\")");
109
- }
110
- if (!code.match(/stability:\s*['"](?:experimental|beta|stable|deprecated)['"]/)) warnings.push("Missing or invalid stability field");
111
- }
112
- function validateDataViewSpec(code, errors, _warnings) {
113
- if (!code.match(/:\s*DataViewSpec\s*=/)) errors.push("Missing DataViewSpec type annotation");
114
- if (!code.includes("meta:")) errors.push("Missing meta section");
115
- if (!code.includes("source:")) errors.push("Missing source section");
116
- if (!code.includes("view:")) errors.push("Missing view section");
117
- if (!code.match(/kind:\s*['"](list|table|detail|grid)['"]/)) errors.push("Missing or invalid view.kind (list/table/detail/grid)");
118
- if (!code.match(/fields:\s*\[/)) errors.push("No fields defined for data view");
119
- }
120
-
121
- //#endregion
122
- export { validateSpecStructure };
1
+ function e(e,d){let f=[],p=[];return/export\s+(const|let)\s+\w+/.test(e)||f.push(`No exported spec found`),d.includes(`.contracts.`)&&t(e,f,p),d.includes(`.event.`)&&a(e,f,p),d.includes(`.presentation.`)&&o(e,f,p),d.includes(`.workflow.`)&&s(e,f,p),d.includes(`.data-view.`)&&u(e,f,p),d.includes(`.migration.`)&&c(e,f,p),d.includes(`.telemetry.`)&&n(e,f,p),d.includes(`.experiment.`)&&r(e,f,p),d.includes(`.app-config.`)&&i(e,f,p),l(e,f,p),{valid:f.length===0,errors:f,warnings:p}}function t(e,t,n){/define(Command|Query)/.test(e)||t.push(`Missing defineCommand or defineQuery call`),e.includes(`meta:`)||t.push(`Missing meta section`),e.includes(`io:`)||t.push(`Missing io section`),e.includes(`policy:`)||t.push(`Missing policy section`),e.match(/name:\s*['"][^'"]+['"]/)||t.push(`Missing or invalid name field`),e.match(/version:\s*\d+/)||t.push(`Missing or invalid version field`);let r=/defineCommand\s*\(/.test(e),i=/defineQuery\s*\(/.test(e),a=/kind:\s*['"](?:command|query)['"]/.test(e);!r&&!i&&!a&&t.push(`Missing kind: use defineCommand(), defineQuery(), or explicit kind field`),e.includes(`acceptance:`)||n.push(`No acceptance scenarios defined`),e.includes(`examples:`)||n.push(`No examples provided`),e.includes(`TODO`)&&n.push(`Contains TODO items that need completion`)}function n(e,t,n){e.match(/:\s*TelemetrySpec\s*=/)||t.push(`Missing TelemetrySpec type annotation`),e.match(/meta:\s*{[\s\S]*name:/)||t.push(`TelemetrySpec.meta is required`),e.includes(`events:`)||t.push(`TelemetrySpec must declare events`),e.match(/privacy:\s*'(public|internal|pii|sensitive)'/)||n.push(`No explicit privacy classification found`)}function r(e,t,n){e.match(/:\s*ExperimentSpec\s*=/)||t.push(`Missing ExperimentSpec type annotation`),e.includes(`controlVariant`)||t.push(`ExperimentSpec must declare controlVariant`),e.includes(`variants:`)||t.push(`ExperimentSpec must declare variants`),e.match(/allocation:\s*{/)||n.push(`ExperimentSpec missing allocation configuration`)}function i(e,t,n){e.match(/:\s*AppBlueprintSpec\s*=/)||t.push(`Missing AppBlueprintSpec type annotation`),e.includes(`meta:`)||t.push(`AppBlueprintSpec must define meta`),e.includes(`appId`)||n.push(`AppBlueprint meta missing appId assignment`),e.includes(`capabilities`)||n.push(`App blueprint spec does not declare capabilities`)}function a(e,t,n){e.includes(`defineEvent`)||t.push(`Missing defineEvent call`),e.match(/name:\s*['"][^'"]+['"]/)||t.push(`Missing or invalid name field`),e.match(/version:\s*\d+/)||t.push(`Missing or invalid version field`),e.includes(`payload:`)||t.push(`Missing payload field`);let r=e.match(/name:\s*['"]([^'"]+)['"]/);r?.[1]&&((r[1].split(`.`).pop()??``).match(/(ed|created|updated|deleted|completed)$/i)||n.push(`Event name should use past tense (e.g., "created", "updated")`))}function o(e,t,n){e.match(/:\s*PresentationSpec\s*=/)||t.push(`Missing PresentationSpec type annotation`),e.includes(`meta:`)||t.push(`Missing meta section`),e.includes(`content:`)||t.push(`Missing content section`),e.match(/kind:\s*['"](?:web_component|markdown|data)['"]/)||t.push(`Missing or invalid kind field`)}function s(e,t,n){e.match(/:\s*WorkflowSpec\s*=/)||t.push(`Missing WorkflowSpec type annotation`),e.includes(`definition:`)||t.push(`Missing definition section`),e.includes(`steps:`)||t.push(`Workflow must declare steps`),e.includes(`transitions:`)||n.push(`No transitions declared; workflow will complete after first step.`),e.match(/title:\s*['"][^'"]+['"]/)||n.push(`Missing workflow title`),e.match(/domain:\s*['"][^'"]+['"]/)||n.push(`Missing domain field`),e.includes(`TODO`)&&n.push(`Contains TODO items that need completion`)}function c(e,t,n){e.match(/:\s*MigrationSpec\s*=/)||t.push(`Missing MigrationSpec type annotation`),e.includes(`plan:`)?e.includes(`up:`)||t.push(`Migration must define at least one up step`):t.push(`Missing plan section`),e.match(/name:\s*['"][^'"]+['"]/)||t.push(`Missing or invalid migration name`),e.match(/version:\s*\d+/)||t.push(`Missing or invalid migration version`),e.includes(`TODO`)&&n.push(`Contains TODO items that need completion`)}function l(e,t,n){e.includes(`SchemaModel`)&&!e.includes(`from '@lssm/lib.schema'`)&&t.push(`Missing import for SchemaModel from @lssm/lib.schema`),e.includes(`from '@lssm/lib.contracts'`)||t.push(`Missing import from @lssm/lib.contracts`);let r=e.match(/owners:\s*\[(.*?)\]/s);r?.[1]&&(r[1].includes(`@`)||n.push(`Owners should start with @ (e.g., "@team")`)),e.match(/stability:\s*['"](?:experimental|beta|stable|deprecated)['"]/)||n.push(`Missing or invalid stability field`)}function u(e,t,n){e.match(/:\s*DataViewSpec\s*=/)||t.push(`Missing DataViewSpec type annotation`),e.includes(`meta:`)||t.push(`Missing meta section`),e.includes(`source:`)||t.push(`Missing source section`),e.includes(`view:`)||t.push(`Missing view section`),e.match(/kind:\s*['"](list|table|detail|grid)['"]/)||t.push(`Missing or invalid view.kind (list/table/detail/grid)`),e.match(/fields:\s*\[/)||t.push(`No fields defined for data view`)}export{e as validateSpecStructure};
package/dist/index.js CHANGED
@@ -1,25 +1 @@
1
- import { DEFAULT_WORKSPACE_CONFIG } from "./types/generation-types.js";
2
- import { extractEmittedEvents, extractPolicyRefs, extractTestRefs, inferSpecTypeFromFilePath, scanAllSpecsFromSource, scanSpecSource } from "./analysis/spec-scan.js";
3
- import { isFeatureFile, scanFeatureSource } from "./analysis/feature-scan.js";
4
- import { computeSemanticDiff } from "./analysis/diff/semantic.js";
5
- import { addContractNode, buildReverseEdges, createContractGraph, detectCycles, findMissingDependencies, toDot } from "./analysis/deps/graph.js";
6
- import { parseImportedSpecNames } from "./analysis/deps/parse-imports.js";
7
- import { validateSpecStructure } from "./analysis/validate/spec-structure.js";
8
- import { capitalize, escapeString, toCamelCase, toKebabCase, toPascalCase } from "./templates/utils.js";
9
- import { generateOperationSpec } from "./templates/operation.js";
10
- import { generateEventSpec } from "./templates/event.js";
11
- import { generatePresentationSpec } from "./templates/presentation.js";
12
- import { generateWorkflowSpec } from "./templates/workflow.js";
13
- import { generateWorkflowRunnerTemplate } from "./templates/workflow-runner.js";
14
- import { generateDataViewSpec } from "./templates/data-view.js";
15
- import { generateTelemetrySpec } from "./templates/telemetry.js";
16
- import { generateExperimentSpec } from "./templates/experiment.js";
17
- import { generateAppBlueprintSpec } from "./templates/app-config.js";
18
- import { generateMigrationSpec } from "./templates/migration.js";
19
- import { generateIntegrationSpec } from "./templates/integration.js";
20
- import { generateKnowledgeSpaceSpec } from "./templates/knowledge.js";
21
- import { generateComponentTemplate, generateHandlerTemplate, generateTestTemplate } from "./templates/handler.js";
22
- import { addExampleContext, buildEventSpecPrompt, buildOperationSpecPrompt, buildPresentationSpecPrompt, getSystemPrompt } from "./ai/spec-creation.js";
23
- import { buildComponentPrompt, buildFormPrompt, buildHandlerPrompt, buildTestPrompt, getCodeGenSystemPrompt } from "./ai/code-generation.js";
24
-
25
- export { DEFAULT_WORKSPACE_CONFIG, addContractNode, addExampleContext, buildComponentPrompt, buildEventSpecPrompt, buildFormPrompt, buildHandlerPrompt, buildOperationSpecPrompt, buildPresentationSpecPrompt, buildReverseEdges, buildTestPrompt, capitalize, computeSemanticDiff, createContractGraph, detectCycles, escapeString, extractEmittedEvents, extractPolicyRefs, extractTestRefs, findMissingDependencies, generateAppBlueprintSpec, generateComponentTemplate, generateDataViewSpec, generateEventSpec, generateExperimentSpec, generateHandlerTemplate, generateIntegrationSpec, generateKnowledgeSpaceSpec, generateMigrationSpec, generateOperationSpec, generatePresentationSpec, generateTelemetrySpec, generateTestTemplate, generateWorkflowRunnerTemplate, generateWorkflowSpec, getCodeGenSystemPrompt, getSystemPrompt, inferSpecTypeFromFilePath, isFeatureFile, parseImportedSpecNames, scanAllSpecsFromSource, scanFeatureSource, scanSpecSource, toCamelCase, toDot, toKebabCase, toPascalCase, validateSpecStructure };
1
+ import{DEFAULT_WORKSPACE_CONFIG as e}from"./types/generation-types.js";import{extractEmittedEvents as t,extractPolicyRefs as n,extractTestRefs as r,inferSpecTypeFromFilePath as i,scanAllSpecsFromSource as a,scanSpecSource as o}from"./analysis/spec-scan.js";import{isFeatureFile as s,scanFeatureSource as c}from"./analysis/feature-scan.js";import{computeSemanticDiff as l}from"./analysis/diff/semantic.js";import{addContractNode as u,buildReverseEdges as d,createContractGraph as f,detectCycles as p,findMissingDependencies as m,toDot as h}from"./analysis/deps/graph.js";import{parseImportedSpecNames as g}from"./analysis/deps/parse-imports.js";import{validateSpecStructure as _}from"./analysis/validate/spec-structure.js";import{capitalize as v,escapeString as y,toCamelCase as b,toKebabCase as x,toPascalCase as S}from"./templates/utils.js";import{generateOperationSpec as C}from"./templates/operation.js";import{generateEventSpec as w}from"./templates/event.js";import{generatePresentationSpec as T}from"./templates/presentation.js";import{generateWorkflowSpec as E}from"./templates/workflow.js";import{generateWorkflowRunnerTemplate as D}from"./templates/workflow-runner.js";import{generateDataViewSpec as O}from"./templates/data-view.js";import{generateTelemetrySpec as k}from"./templates/telemetry.js";import{generateExperimentSpec as A}from"./templates/experiment.js";import{generateAppBlueprintSpec as j}from"./templates/app-config.js";import{generateMigrationSpec as M}from"./templates/migration.js";import{generateIntegrationSpec as N}from"./templates/integration.js";import{generateKnowledgeSpaceSpec as P}from"./templates/knowledge.js";import{generateComponentTemplate as F,generateHandlerTemplate as I,generateTestTemplate as L}from"./templates/handler.js";import{addExampleContext as R,buildEventSpecPrompt as z,buildOperationSpecPrompt as B,buildPresentationSpecPrompt as V,getSystemPrompt as H}from"./ai/spec-creation.js";import{buildComponentPrompt as U,buildFormPrompt as W,buildHandlerPrompt as G,buildTestPrompt as K,getCodeGenSystemPrompt as q}from"./ai/code-generation.js";export{e as DEFAULT_WORKSPACE_CONFIG,u as addContractNode,R as addExampleContext,U as buildComponentPrompt,z as buildEventSpecPrompt,W as buildFormPrompt,G as buildHandlerPrompt,B as buildOperationSpecPrompt,V as buildPresentationSpecPrompt,d as buildReverseEdges,K as buildTestPrompt,v as capitalize,l as computeSemanticDiff,f as createContractGraph,p as detectCycles,y as escapeString,t as extractEmittedEvents,n as extractPolicyRefs,r as extractTestRefs,m as findMissingDependencies,j as generateAppBlueprintSpec,F as generateComponentTemplate,O as generateDataViewSpec,w as generateEventSpec,A as generateExperimentSpec,I as generateHandlerTemplate,N as generateIntegrationSpec,P as generateKnowledgeSpaceSpec,M as generateMigrationSpec,C as generateOperationSpec,T as generatePresentationSpec,k as generateTelemetrySpec,L as generateTestTemplate,D as generateWorkflowRunnerTemplate,E as generateWorkflowSpec,q as getCodeGenSystemPrompt,H as getSystemPrompt,i as inferSpecTypeFromFilePath,s as isFeatureFile,g as parseImportedSpecNames,a as scanAllSpecsFromSource,c as scanFeatureSource,o as scanSpecSource,b as toCamelCase,h as toDot,x as toKebabCase,S as toPascalCase,_ as validateSpecStructure};