@cordiacode/core 0.1.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 (50) hide show
  1. package/LICENSE +201 -0
  2. package/dist/compiler/compiler.d.ts +28 -0
  3. package/dist/compiler/compiler.d.ts.map +1 -0
  4. package/dist/compiler/compiler.js +83 -0
  5. package/dist/compiler/compiler.js.map +1 -0
  6. package/dist/compiler/index.d.ts +2 -0
  7. package/dist/compiler/index.d.ts.map +1 -0
  8. package/dist/compiler/index.js +2 -0
  9. package/dist/compiler/index.js.map +1 -0
  10. package/dist/errors.d.ts +27 -0
  11. package/dist/errors.d.ts.map +1 -0
  12. package/dist/errors.js +24 -0
  13. package/dist/errors.js.map +1 -0
  14. package/dist/index.d.ts +15 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +15 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/lexer/index.d.ts +3 -0
  19. package/dist/lexer/index.d.ts.map +1 -0
  20. package/dist/lexer/index.js +3 -0
  21. package/dist/lexer/index.js.map +1 -0
  22. package/dist/lexer/lexer.d.ts +22 -0
  23. package/dist/lexer/lexer.d.ts.map +1 -0
  24. package/dist/lexer/lexer.js +170 -0
  25. package/dist/lexer/lexer.js.map +1 -0
  26. package/dist/lexer/token.d.ts +78 -0
  27. package/dist/lexer/token.d.ts.map +1 -0
  28. package/dist/lexer/token.js +68 -0
  29. package/dist/lexer/token.js.map +1 -0
  30. package/dist/parser/ast.d.ts +59 -0
  31. package/dist/parser/ast.d.ts.map +1 -0
  32. package/dist/parser/ast.js +32 -0
  33. package/dist/parser/ast.js.map +1 -0
  34. package/dist/parser/index.d.ts +3 -0
  35. package/dist/parser/index.d.ts.map +1 -0
  36. package/dist/parser/index.js +3 -0
  37. package/dist/parser/index.js.map +1 -0
  38. package/dist/parser/parser.d.ts +30 -0
  39. package/dist/parser/parser.d.ts.map +1 -0
  40. package/dist/parser/parser.js +164 -0
  41. package/dist/parser/parser.js.map +1 -0
  42. package/dist/validator/index.d.ts +2 -0
  43. package/dist/validator/index.d.ts.map +1 -0
  44. package/dist/validator/index.js +2 -0
  45. package/dist/validator/index.js.map +1 -0
  46. package/dist/validator/validator.d.ts +41 -0
  47. package/dist/validator/validator.d.ts.map +1 -0
  48. package/dist/validator/validator.js +138 -0
  49. package/dist/validator/validator.js.map +1 -0
  50. package/package.json +48 -0
@@ -0,0 +1,138 @@
1
+ import { parse } from '../parser/index.js';
2
+ /** Machine-readable validator error codes. */
3
+ export const ValidationErrorCode = {
4
+ MissingGoal: 'CORDIA_VAL_MISSING_GOAL',
5
+ MultipleGoals: 'CORDIA_VAL_MULTIPLE_GOALS',
6
+ EmptyValue: 'CORDIA_VAL_EMPTY_VALUE',
7
+ Duplicate: 'CORDIA_VAL_DUPLICATE',
8
+ DuplicateMilestone: 'CORDIA_VAL_DUPLICATE_MILESTONE',
9
+ TestMissingArrow: 'CORDIA_VAL_TEST_MISSING_ARROW',
10
+ TestEmptyInput: 'CORDIA_VAL_TEST_EMPTY_INPUT',
11
+ TestEmptyExpected: 'CORDIA_VAL_TEST_EMPTY_EXPECTED',
12
+ };
13
+ /**
14
+ * Semantically validate a parsed {@link SpecAst}.
15
+ *
16
+ * Enforces the rules the grammar/schema cannot express on their own
17
+ * (`spec/ambiguities.md`): exactly one goal, no empty values, well-formed
18
+ * tests, and no duplicates in the lists where repetition is meaningless. Every
19
+ * diagnostic carries an error code and the offending node's line/column —
20
+ * "validation rejects, never guesses."
21
+ */
22
+ export function validate(spec) {
23
+ const errors = [];
24
+ const add = (code, message, at) => {
25
+ errors.push({ code, message, line: at.line, column: at.column });
26
+ };
27
+ // --- Goal cardinality (exactly one). ---
28
+ if (spec.goals.length === 0) {
29
+ errors.push({
30
+ code: ValidationErrorCode.MissingGoal,
31
+ message: 'Specification is missing a goal (`[ … ]`)',
32
+ line: 1,
33
+ column: 1,
34
+ });
35
+ }
36
+ else {
37
+ for (const extra of spec.goals.slice(1)) {
38
+ add(ValidationErrorCode.MultipleGoals, 'Only one goal (`[ … ]`) is allowed', extra);
39
+ }
40
+ }
41
+ // --- Empty values: every construct must carry non-empty text. ---
42
+ const valueLists = [
43
+ ['goal', spec.goals],
44
+ ['context entry', spec.context],
45
+ ['inspiration', spec.inspirations],
46
+ ['tech-stack item', spec.stack],
47
+ ['agent', spec.agents],
48
+ ['feature', spec.features],
49
+ ['exclusion', spec.exclusions],
50
+ ['requirement', spec.requirements],
51
+ ['priority', spec.priorities],
52
+ ['rule', spec.rules],
53
+ ['file', spec.files],
54
+ ['success criterion', spec.successCriteria],
55
+ ['deliverable', spec.deliverables],
56
+ ['question', spec.questions],
57
+ ['debug task', spec.debugTasks],
58
+ ];
59
+ for (const [label, nodes] of valueLists) {
60
+ for (const node of nodes) {
61
+ if (node.value.trim() === '')
62
+ add(ValidationErrorCode.EmptyValue, `Empty ${label}`, node);
63
+ }
64
+ }
65
+ // --- Tests: must split into non-empty input and expected. ---
66
+ for (const test of spec.tests) {
67
+ if (!test.hasArrow) {
68
+ add(ValidationErrorCode.TestMissingArrow, 'Test must be written as `input -> expected`', test);
69
+ continue;
70
+ }
71
+ if (test.input.trim() === '')
72
+ add(ValidationErrorCode.TestEmptyInput, 'Test input is empty', test);
73
+ if (test.expected.trim() === '') {
74
+ add(ValidationErrorCode.TestEmptyExpected, 'Test expected value is empty', test);
75
+ }
76
+ }
77
+ // --- Milestones: non-empty names and features. ---
78
+ for (const milestone of spec.milestones) {
79
+ if (milestone.name.trim() === '') {
80
+ add(ValidationErrorCode.EmptyValue, 'Empty milestone name', milestone);
81
+ }
82
+ for (const feature of milestone.features) {
83
+ if (feature.value.trim() === '') {
84
+ add(ValidationErrorCode.EmptyValue, 'Empty milestone feature', feature);
85
+ }
86
+ }
87
+ }
88
+ // --- Duplicates where repetition is meaningless (ambiguities §7). ---
89
+ const dedupeLists = [
90
+ ['feature', spec.features],
91
+ ['exclusion', spec.exclusions],
92
+ ['requirement', spec.requirements],
93
+ ['priority', spec.priorities],
94
+ ['rule', spec.rules],
95
+ ['file', spec.files],
96
+ ['agent', spec.agents],
97
+ ['inspiration', spec.inspirations],
98
+ ['tech-stack item', spec.stack],
99
+ ['deliverable', spec.deliverables],
100
+ ];
101
+ for (const [label, nodes] of dedupeLists) {
102
+ const seen = new Set();
103
+ for (const node of nodes) {
104
+ const key = node.value.trim();
105
+ if (key === '')
106
+ continue; // already reported as empty
107
+ if (seen.has(key))
108
+ add(ValidationErrorCode.Duplicate, `Duplicate ${label}: "${key}"`, node);
109
+ else
110
+ seen.add(key);
111
+ }
112
+ }
113
+ // --- Duplicate milestone names. ---
114
+ const seenMilestones = new Set();
115
+ for (const milestone of spec.milestones) {
116
+ const key = milestone.name.trim();
117
+ if (key === '')
118
+ continue;
119
+ if (seenMilestones.has(key)) {
120
+ add(ValidationErrorCode.DuplicateMilestone, `Duplicate milestone: "${key}"`, milestone);
121
+ }
122
+ else {
123
+ seenMilestones.add(key);
124
+ }
125
+ }
126
+ return { errors };
127
+ }
128
+ /**
129
+ * Lex, parse, and validate VibeSpec source in one call. Diagnostics are
130
+ * concatenated in pipeline order (lexer → parser → validator). This is the
131
+ * entry point the CLI's `bloom validate` will use.
132
+ */
133
+ export function analyze(source) {
134
+ const { spec, errors } = parse(source);
135
+ const { errors: validationErrors } = validate(spec);
136
+ return { spec, errors: [...errors, ...validationErrors] };
137
+ }
138
+ //# sourceMappingURL=validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/validator/validator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C,8CAA8C;AAC9C,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,WAAW,EAAE,yBAAyB;IACtC,aAAa,EAAE,2BAA2B;IAC1C,UAAU,EAAE,wBAAwB;IACpC,SAAS,EAAE,sBAAsB;IACjC,kBAAkB,EAAE,gCAAgC;IACpD,gBAAgB,EAAE,+BAA+B;IAC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1.0",
4
+ "description": "Bloom compiler for Cordia VibeSpec: lexer, parser, validator, and Prompt JSON compiler.",
5
+ "license": "Apache-2.0",
6
+ "author": "Parth Verma",
7
+ "type": "module",
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "LICENSE"
19
+ ],
20
+ "keywords": [
21
+ "cordia",
22
+ "vibespec",
23
+ "compiler",
24
+ "intent",
25
+ "prompt",
26
+ "bloom"
27
+ ],
28
+ "engines": {
29
+ "node": ">=20"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/Parthverma-0/cordia.git",
34
+ "directory": "packages/core"
35
+ },
36
+ "homepage": "https://github.com/Parthverma-0/cordia#readme",
37
+ "bugs": "https://github.com/Parthverma-0/cordia/issues",
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "dependencies": {
42
+ "@cordiacode/schema": "0.1.0"
43
+ },
44
+ "scripts": {
45
+ "build": "tsc",
46
+ "typecheck": "tsc --noEmit"
47
+ }
48
+ }