@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
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Parth Verma
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,28 @@
1
+ import type { CordiaPrompt } from '@cordiacode/schema';
2
+ import type { SpecAst } from '../parser/ast.js';
3
+ /** The spec version stamped into every compiled document's metadata. */
4
+ export declare const CORDIA_PROMPT_VERSION = "Dichotoma-1.0";
5
+ /**
6
+ * Compile a (validated) {@link SpecAst} into a {@link CordiaPrompt} object.
7
+ *
8
+ * Guarantees from the compiler contract (`spec/ambiguities.md` §12, Project
9
+ * Hub rules):
10
+ * - The six top-level keys are always present, in fixed order: metadata,
11
+ * project, implementation, validation, deliverables, execution.
12
+ * - Section sub-keys are inserted in their canonical order and **omitted** when
13
+ * empty (no empty arrays/objects).
14
+ * - Output is deterministic: identical input yields an identical object (and,
15
+ * via {@link compileToJson}, byte-identical text). No timestamps, no
16
+ * iteration-order surprises.
17
+ *
18
+ * The input is assumed to have passed validation; the goal is read from the
19
+ * first goal node.
20
+ */
21
+ export declare function compile(spec: SpecAst): CordiaPrompt;
22
+ /**
23
+ * Serialize a compiled prompt to its canonical, deterministic JSON text:
24
+ * 2-space indentation and a trailing newline. This is the byte-for-byte output
25
+ * format the golden/determinism tests assert against.
26
+ */
27
+ export declare function compileToJson(spec: SpecAst): string;
28
+ //# sourceMappingURL=compiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../src/compiler/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,OAAO,EAAa,MAAM,kBAAkB,CAAC;AAE3D,wEAAwE;AACxE,eAAO,MAAM,qBAAqB,kBAAkB,CAAC;AAOrD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,YAAY,CAyCnD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAEnD"}
@@ -0,0 +1,83 @@
1
+ /** The spec version stamped into every compiled document's metadata. */
2
+ export const CORDIA_PROMPT_VERSION = 'Dichotoma-1.0';
3
+ /** Project a list of value nodes onto their raw string values. */
4
+ function values(nodes) {
5
+ return nodes.map((node) => node.value);
6
+ }
7
+ /**
8
+ * Compile a (validated) {@link SpecAst} into a {@link CordiaPrompt} object.
9
+ *
10
+ * Guarantees from the compiler contract (`spec/ambiguities.md` §12, Project
11
+ * Hub rules):
12
+ * - The six top-level keys are always present, in fixed order: metadata,
13
+ * project, implementation, validation, deliverables, execution.
14
+ * - Section sub-keys are inserted in their canonical order and **omitted** when
15
+ * empty (no empty arrays/objects).
16
+ * - Output is deterministic: identical input yields an identical object (and,
17
+ * via {@link compileToJson}, byte-identical text). No timestamps, no
18
+ * iteration-order surprises.
19
+ *
20
+ * The input is assumed to have passed validation; the goal is read from the
21
+ * first goal node.
22
+ */
23
+ export function compile(spec) {
24
+ const project = { goal: spec.goals[0]?.value ?? '' };
25
+ if (spec.context.length > 0)
26
+ project.context = values(spec.context);
27
+ if (spec.inspirations.length > 0)
28
+ project.inspirations = values(spec.inspirations);
29
+ const implementation = {};
30
+ if (spec.stack.length > 0)
31
+ implementation.stack = values(spec.stack);
32
+ if (spec.agents.length > 0)
33
+ implementation.agents = values(spec.agents);
34
+ if (spec.features.length > 0)
35
+ implementation.features = values(spec.features);
36
+ if (spec.exclusions.length > 0)
37
+ implementation.exclusions = values(spec.exclusions);
38
+ if (spec.requirements.length > 0)
39
+ implementation.requirements = values(spec.requirements);
40
+ if (spec.priorities.length > 0)
41
+ implementation.priorities = values(spec.priorities);
42
+ if (spec.rules.length > 0)
43
+ implementation.rules = values(spec.rules);
44
+ if (spec.files.length > 0)
45
+ implementation.files = values(spec.files);
46
+ const validation = {};
47
+ if (spec.tests.length > 0)
48
+ validation.tests = spec.tests.map((test) => test.value);
49
+ if (spec.successCriteria.length > 0)
50
+ validation.success_criteria = values(spec.successCriteria);
51
+ const deliverables = {};
52
+ if (spec.deliverables.length > 0)
53
+ deliverables.outputs = values(spec.deliverables);
54
+ const execution = {};
55
+ if (spec.milestones.length > 0) {
56
+ const milestones = {};
57
+ for (const milestone of spec.milestones) {
58
+ milestones[milestone.name] = values(milestone.features);
59
+ }
60
+ execution.milestones = milestones;
61
+ }
62
+ if (spec.questions.length > 0)
63
+ execution.questions = values(spec.questions);
64
+ if (spec.debugTasks.length > 0)
65
+ execution.debug_tasks = values(spec.debugTasks);
66
+ return {
67
+ metadata: { language: 'Cordia', version: CORDIA_PROMPT_VERSION },
68
+ project,
69
+ implementation,
70
+ validation,
71
+ deliverables,
72
+ execution,
73
+ };
74
+ }
75
+ /**
76
+ * Serialize a compiled prompt to its canonical, deterministic JSON text:
77
+ * 2-space indentation and a trailing newline. This is the byte-for-byte output
78
+ * format the golden/determinism tests assert against.
79
+ */
80
+ export function compileToJson(spec) {
81
+ return `${JSON.stringify(compile(spec), null, 2)}\n`;
82
+ }
83
+ //# sourceMappingURL=compiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.js","sourceRoot":"","sources":["../../src/compiler/compiler.ts"],"names":[],"mappings":"AAGA,wEAAwE;AACxE,MAAM,CAAC,MAAM,qBAAqB,GAAG,eAAe,CAAC;AAErD,kEAAkE;AAClE,SAAS,MAAM,CAAC,KAA2B;IACzC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC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AAC,SAAS,CAAC,CAAC;IAC5E,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC;QAAE,SAAS,CAAC,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAEhF,OAAO;QACL,QAAQ,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,qBAAqB,EAAE;QAChE,OAAO;QACP,cAAc;QACd,UAAU;QACV,YAAY;QACZ,SAAS;KACV,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,IAAa;IACzC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;AACvD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './compiler.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compiler/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './compiler.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/compiler/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Shared error model for the Bloom compiler. Every stage (lexer, parser,
3
+ * validator) reports problems as {@link CordiaError} records carrying a stable
4
+ * machine-readable `code` plus 1-based line/column for editor-friendly
5
+ * diagnostics.
6
+ */
7
+ /** A single diagnostic with source position. */
8
+ export interface CordiaError {
9
+ /** Stable, machine-readable error code (e.g. `CORDIA_LEX_UNKNOWN_PREFIX`). */
10
+ code: string;
11
+ /** Human-readable description. */
12
+ message: string;
13
+ /** 1-based line number. */
14
+ line: number;
15
+ /** 1-based column number. */
16
+ column: number;
17
+ }
18
+ /** Format a {@link CordiaError} as a single diagnostic line. */
19
+ export declare function formatError(error: CordiaError): string;
20
+ /** Throwable wrapper around a {@link CordiaError}. */
21
+ export declare class CordiaSyntaxError extends Error {
22
+ readonly code: string;
23
+ readonly line: number;
24
+ readonly column: number;
25
+ constructor(error: CordiaError);
26
+ }
27
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,gDAAgD;AAChD,MAAM,WAAW,WAAW;IAC1B,8EAA8E;IAC9E,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,2BAA2B;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,gEAAgE;AAChE,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAEtD;AAED,sDAAsD;AACtD,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,KAAK,EAAE,WAAW;CAO/B"}
package/dist/errors.js ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Shared error model for the Bloom compiler. Every stage (lexer, parser,
3
+ * validator) reports problems as {@link CordiaError} records carrying a stable
4
+ * machine-readable `code` plus 1-based line/column for editor-friendly
5
+ * diagnostics.
6
+ */
7
+ /** Format a {@link CordiaError} as a single diagnostic line. */
8
+ export function formatError(error) {
9
+ return `[${error.code}] ${error.message} (line ${error.line}, col ${error.column})`;
10
+ }
11
+ /** Throwable wrapper around a {@link CordiaError}. */
12
+ export class CordiaSyntaxError extends Error {
13
+ code;
14
+ line;
15
+ column;
16
+ constructor(error) {
17
+ super(formatError(error));
18
+ this.name = 'CordiaSyntaxError';
19
+ this.code = error.code;
20
+ this.line = error.line;
21
+ this.column = error.column;
22
+ }
23
+ }
24
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAcH,gEAAgE;AAChE,MAAM,UAAU,WAAW,CAAC,KAAkB;IAC5C,OAAO,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,UAAU,KAAK,CAAC,IAAI,SAAS,KAAK,CAAC,MAAM,GAAG,CAAC;AACtF,CAAC;AAED,sDAAsD;AACtD,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACjC,IAAI,CAAS;IACb,IAAI,CAAS;IACb,MAAM,CAAS;IAExB,YAAY,KAAkB;QAC5B,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC7B,CAAC;CACF"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @cordiacode/core — the Bloom compiler.
3
+ *
4
+ * Pipeline: Lexer → Parser → Validator → Prompt Compiler, transforming
5
+ * VibeSpec (.cordia) into deterministic Cordia Prompt JSON.
6
+ *
7
+ * Phases implemented: lexer (2), parser (3), validator (4), compiler (5).
8
+ */
9
+ export declare const CORDIA_SPEC_VERSION = "Dichotoma-1.0";
10
+ export * from './errors.js';
11
+ export * from './lexer/index.js';
12
+ export * from './parser/index.js';
13
+ export * from './validator/index.js';
14
+ export * from './compiler/index.js';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AAEnD,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @cordiacode/core — the Bloom compiler.
3
+ *
4
+ * Pipeline: Lexer → Parser → Validator → Prompt Compiler, transforming
5
+ * VibeSpec (.cordia) into deterministic Cordia Prompt JSON.
6
+ *
7
+ * Phases implemented: lexer (2), parser (3), validator (4), compiler (5).
8
+ */
9
+ export const CORDIA_SPEC_VERSION = 'Dichotoma-1.0';
10
+ export * from './errors.js';
11
+ export * from './lexer/index.js';
12
+ export * from './parser/index.js';
13
+ export * from './validator/index.js';
14
+ export * from './compiler/index.js';
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,eAAe,CAAC;AAEnD,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './token.js';
2
+ export * from './lexer.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lexer/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './token.js';
2
+ export * from './lexer.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lexer/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { CordiaError } from '../errors.js';
2
+ import { type Token } from './token.js';
3
+ /** The result of lexing a `.cordia` source string. */
4
+ export interface LexResult {
5
+ /** Tokens in source order, terminated by a single `EOF` token. */
6
+ tokens: Token[];
7
+ /** Syntax errors collected during lexing (empty if the input is clean). */
8
+ errors: CordiaError[];
9
+ }
10
+ /**
11
+ * Tokenize VibeSpec source into a flat token stream.
12
+ *
13
+ * The lexer is line-oriented and stateful: it classifies each non-blank line by
14
+ * its leading symbol, treats the body of a context block (`{ … }`) as opaque
15
+ * text, and groups milestone bodies (`>> Name { + … }`). It is **error-tolerant**
16
+ * — recoverable problems are collected into {@link LexResult.errors} and lexing
17
+ * continues, so a single file can report many diagnostics at once.
18
+ *
19
+ * @see `spec/grammar.md` and `spec/ambiguities.md`
20
+ */
21
+ export declare function tokenize(source: string): LexResult;
22
+ //# sourceMappingURL=lexer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lexer.d.ts","sourceRoot":"","sources":["../../src/lexer/lexer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAoC,KAAK,KAAK,EAAa,MAAM,YAAY,CAAC;AAErF,sDAAsD;AACtD,MAAM,WAAW,SAAS;IACxB,kEAAkE;IAClE,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,2EAA2E;IAC3E,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB;AAKD;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAyNlD"}
@@ -0,0 +1,170 @@
1
+ import { LexErrorCode, SINGLE_CHAR_PREFIX, TokenType } from './token.js';
2
+ /**
3
+ * Tokenize VibeSpec source into a flat token stream.
4
+ *
5
+ * The lexer is line-oriented and stateful: it classifies each non-blank line by
6
+ * its leading symbol, treats the body of a context block (`{ … }`) as opaque
7
+ * text, and groups milestone bodies (`>> Name { + … }`). It is **error-tolerant**
8
+ * — recoverable problems are collected into {@link LexResult.errors} and lexing
9
+ * continues, so a single file can report many diagnostics at once.
10
+ *
11
+ * @see `spec/grammar.md` and `spec/ambiguities.md`
12
+ */
13
+ export function tokenize(source) {
14
+ const tokens = [];
15
+ const errors = [];
16
+ const lines = source.split(/\r?\n/);
17
+ let mode = 'normal';
18
+ // Line where the currently-open block started, for unterminated-block errors.
19
+ let blockStartLine = 0;
20
+ // Set after a bare `>> Name` header that still needs its `{` body opener.
21
+ let pendingMilestone = false;
22
+ const emit = (type, value, line, column, raw) => {
23
+ tokens.push({ type, value, line, column, raw });
24
+ };
25
+ const fail = (code, message, line, column) => {
26
+ errors.push({ code, message, line, column });
27
+ };
28
+ for (let i = 0; i < lines.length; i++) {
29
+ const raw = lines[i] ?? '';
30
+ const lineNo = i + 1;
31
+ const trimmed = raw.trim();
32
+ const startCol = raw.length - raw.trimStart().length + 1;
33
+ // --- Context block: body is opaque; only a lone `}` closes it. ---
34
+ if (mode === 'context') {
35
+ if (trimmed === '}') {
36
+ emit(TokenType.ContextClose, '', lineNo, startCol, raw);
37
+ mode = 'normal';
38
+ }
39
+ else {
40
+ // Preserve the original line verbatim (blank lines included).
41
+ emit(TokenType.ContextText, raw, lineNo, 1, raw);
42
+ }
43
+ continue;
44
+ }
45
+ // --- Milestone body: only `+` features, until a lone `}`. ---
46
+ if (mode === 'milestone') {
47
+ if (trimmed === '}') {
48
+ emit(TokenType.MilestoneBodyClose, '', lineNo, startCol, raw);
49
+ mode = 'normal';
50
+ }
51
+ else if (trimmed === '') {
52
+ // blank lines inside a milestone body are ignored
53
+ }
54
+ else if (trimmed.startsWith('+')) {
55
+ emit(TokenType.Feature, trimmed.slice(1).trim(), lineNo, startCol, raw);
56
+ }
57
+ else {
58
+ fail(LexErrorCode.MilestoneBadLine, 'Only features (`+ …`) are allowed inside a milestone body', lineNo, startCol);
59
+ }
60
+ continue;
61
+ }
62
+ // --- Awaiting a milestone body opener after a bare `>> Name` header. ---
63
+ if (pendingMilestone) {
64
+ if (trimmed === '')
65
+ continue; // blank lines between header and `{` are fine
66
+ if (trimmed === '{') {
67
+ emit(TokenType.MilestoneBodyOpen, '', lineNo, startCol, raw);
68
+ mode = 'milestone';
69
+ blockStartLine = lineNo;
70
+ pendingMilestone = false;
71
+ continue;
72
+ }
73
+ fail(LexErrorCode.MilestoneMissingBody, 'Expected `{` to open the milestone body after the `>>` header', lineNo, startCol);
74
+ pendingMilestone = false;
75
+ // fall through and classify this line normally
76
+ }
77
+ // --- Normal mode. ---
78
+ if (trimmed === '')
79
+ continue; // blank line
80
+ // Multi-char prefixes first (precedence: `=>` before `=`, `>>` before `>`).
81
+ if (trimmed.startsWith('=>')) {
82
+ emit(TokenType.Deliverable, trimmed.slice(2).trim(), lineNo, startCol, raw);
83
+ continue;
84
+ }
85
+ if (trimmed.startsWith('>>')) {
86
+ const after = trimmed.slice(2).trim();
87
+ if (after.endsWith('{')) {
88
+ // Inline body opener: `>> Name {`
89
+ const name = after.slice(0, -1).trim();
90
+ if (name === '') {
91
+ fail(LexErrorCode.MilestoneMissingName, 'Milestone requires a name', lineNo, startCol);
92
+ continue;
93
+ }
94
+ emit(TokenType.MilestoneHeader, name, lineNo, startCol, raw);
95
+ emit(TokenType.MilestoneBodyOpen, '', lineNo, startCol, raw);
96
+ mode = 'milestone';
97
+ blockStartLine = lineNo;
98
+ }
99
+ else if (after === '') {
100
+ fail(LexErrorCode.MilestoneMissingName, 'Milestone requires a name', lineNo, startCol);
101
+ }
102
+ else {
103
+ emit(TokenType.MilestoneHeader, after, lineNo, startCol, raw);
104
+ pendingMilestone = true;
105
+ blockStartLine = lineNo;
106
+ }
107
+ continue;
108
+ }
109
+ const first = trimmed[0] ?? '';
110
+ // Container forms with paired delimiters.
111
+ if (first === '[') {
112
+ if (!trimmed.endsWith(']')) {
113
+ fail(LexErrorCode.UnterminatedGoal, 'Goal is missing its closing `]`', lineNo, startCol);
114
+ continue;
115
+ }
116
+ emit(TokenType.Goal, trimmed.slice(1, -1).trim(), lineNo, startCol, raw);
117
+ continue;
118
+ }
119
+ if (first === '<') {
120
+ if (!trimmed.endsWith('>')) {
121
+ fail(LexErrorCode.UnterminatedStack, 'Tech stack is missing its closing `>`', lineNo, startCol);
122
+ continue;
123
+ }
124
+ emit(TokenType.Stack, trimmed.slice(1, -1).trim(), lineNo, startCol, raw);
125
+ continue;
126
+ }
127
+ if (first === '(') {
128
+ if (!trimmed.endsWith(')')) {
129
+ fail(LexErrorCode.UnterminatedDebugTask, 'Debug task is missing its closing `)`', lineNo, startCol);
130
+ continue;
131
+ }
132
+ emit(TokenType.DebugTask, trimmed.slice(1, -1).trim(), lineNo, startCol, raw);
133
+ continue;
134
+ }
135
+ if (first === '{') {
136
+ if (trimmed !== '{') {
137
+ fail(LexErrorCode.ContextBraceNotAlone, 'A context block `{` must be on its own line', lineNo, startCol);
138
+ continue;
139
+ }
140
+ emit(TokenType.ContextOpen, '', lineNo, startCol, raw);
141
+ mode = 'context';
142
+ blockStartLine = lineNo;
143
+ continue;
144
+ }
145
+ if (first === '}') {
146
+ fail(LexErrorCode.UnexpectedCloseBrace, 'Unexpected `}`', lineNo, startCol);
147
+ continue;
148
+ }
149
+ // Single-character prefixes.
150
+ const single = SINGLE_CHAR_PREFIX[first];
151
+ if (single !== undefined) {
152
+ emit(single, trimmed.slice(1).trim(), lineNo, startCol, raw);
153
+ continue;
154
+ }
155
+ fail(LexErrorCode.UnknownPrefix, `Unrecognized construct: line does not start with a known symbol`, lineNo, startCol);
156
+ }
157
+ // --- End-of-input: report any unterminated blocks. ---
158
+ if (mode === 'context') {
159
+ fail(LexErrorCode.UnterminatedContext, 'Unterminated context block (missing `}`)', blockStartLine, 1);
160
+ }
161
+ else if (mode === 'milestone') {
162
+ fail(LexErrorCode.UnterminatedMilestone, 'Unterminated milestone body (missing `}`)', blockStartLine, 1);
163
+ }
164
+ else if (pendingMilestone) {
165
+ fail(LexErrorCode.MilestoneMissingBody, 'Milestone header has no body (`{ … }`)', blockStartLine, 1);
166
+ }
167
+ emit(TokenType.EOF, '', lines.length, 1, '');
168
+ return { tokens, errors };
169
+ }
170
+ //# sourceMappingURL=lexer.js.map