@intentius/chant 0.0.16 → 0.0.22
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.
- package/bin/chant +4 -1
- package/package.json +20 -1
- package/src/build.test.ts +4 -2
- package/src/build.ts +3 -0
- package/src/builder.test.ts +3 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/docs/astro.config.mjs +0 -3
- package/src/cli/commands/build.ts +5 -12
- package/src/cli/commands/diff.test.ts +2 -1
- package/src/cli/commands/diff.ts +2 -1
- package/src/cli/commands/init-lexicon.test.ts +0 -9
- package/src/cli/commands/init-lexicon.ts +0 -94
- package/src/cli/commands/init.ts +2 -20
- package/src/cli/handlers/build.ts +3 -3
- package/src/cli/handlers/lint.ts +2 -2
- package/src/cli/handlers/spell.ts +396 -0
- package/src/cli/handlers/state.ts +230 -0
- package/src/cli/lsp/server.test.ts +4 -0
- package/src/cli/main.ts +37 -3
- package/src/cli/mcp/server.test.ts +13 -9
- package/src/cli/mcp/server.ts +220 -6
- package/src/cli/mcp/tools/build.ts +2 -1
- package/src/cli/plugins.ts +1 -1
- package/src/cli/reporters/stylish.test.ts +2 -2
- package/src/cli/reporters/stylish.ts +1 -1
- package/src/codegen/docs.ts +13 -2
- package/src/composite.test.ts +1 -1
- package/src/config.ts +4 -0
- package/src/declarable.test.ts +2 -1
- package/src/declarable.ts +1 -1
- package/src/discovery/graph.test.ts +40 -0
- package/src/discovery/import.test.ts +5 -5
- package/src/discovery/resolve.test.ts +20 -0
- package/src/discovery/resolve.ts +2 -2
- package/src/index.ts +2 -0
- package/src/lexicon.ts +24 -0
- package/src/lint/rule-options.test.ts +3 -3
- package/src/lint/rule-registry.test.ts +1 -1
- package/src/lint/rules/composite-scope.ts +1 -1
- package/src/serializer-walker.ts +2 -1
- package/src/spell/discovery.ts +183 -0
- package/src/spell/index.ts +3 -0
- package/src/spell/prompt.ts +133 -0
- package/src/spell/types.ts +89 -0
- package/src/state/digest.ts +88 -0
- package/src/state/git.ts +317 -0
- package/src/state/index.ts +4 -0
- package/src/state/snapshot.ts +179 -0
- package/src/state/types.ts +59 -0
- package/src/types.ts +2 -1
- package/src/utils.test.ts +16 -3
- package/src/utils.ts +31 -1
- package/src/validation.test.ts +11 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/docs/src/content/docs/getting-started.mdx +0 -6
- package/src/cli/commands/__fixtures__/init-lexicon-output/docs/src/content/docs/lint-rules.mdx +0 -6
- package/src/cli/commands/__fixtures__/init-lexicon-output/docs/src/content/docs/serialization.mdx +0 -6
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/actions/.gitkeep +0 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/composites/.gitkeep +0 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/coverage.ts +0 -11
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/import/generator.ts +0 -10
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/import/parser.ts +0 -10
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/lint/post-synth/.gitkeep +0 -0
package/src/utils.ts
CHANGED
|
@@ -6,6 +6,36 @@ import { AttrRef } from "./attrref";
|
|
|
6
6
|
*/
|
|
7
7
|
export const LOGICAL_NAME_SYMBOL = Symbol.for("chant.logicalName");
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Duck-type check for AttrRef that survives the dual-package hazard.
|
|
11
|
+
* When npm installs separate copies of @intentius/chant (one for the CLI,
|
|
12
|
+
* one for the lexicon), `instanceof AttrRef` fails across package boundaries.
|
|
13
|
+
*/
|
|
14
|
+
export function isAttrRefLike(value: unknown): value is AttrRef {
|
|
15
|
+
if (value instanceof AttrRef) return true;
|
|
16
|
+
return (
|
|
17
|
+
typeof value === "object" &&
|
|
18
|
+
value !== null &&
|
|
19
|
+
"parent" in value &&
|
|
20
|
+
"attribute" in value &&
|
|
21
|
+
"_setLogicalName" in value &&
|
|
22
|
+
typeof (value as any).parent === "object" &&
|
|
23
|
+
typeof (value as any).attribute === "string"
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* JSON.stringify replacer that sorts object keys for deterministic output.
|
|
29
|
+
*/
|
|
30
|
+
export function sortedJsonReplacer(_key: string, value: unknown): unknown {
|
|
31
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
32
|
+
return Object.fromEntries(
|
|
33
|
+
Object.entries(value as Record<string, unknown>).sort(([a], [b]) => a.localeCompare(b))
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
|
|
9
39
|
/**
|
|
10
40
|
* Get all property names that have AttrRef values
|
|
11
41
|
* @param entity - The declarable entity to inspect
|
|
@@ -18,7 +48,7 @@ export function getAttributes(entity: Declarable): string[] {
|
|
|
18
48
|
for (const key in obj) {
|
|
19
49
|
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
20
50
|
const value = obj[key];
|
|
21
|
-
if (value
|
|
51
|
+
if (isAttrRefLike(value)) {
|
|
22
52
|
attributes.push(key);
|
|
23
53
|
}
|
|
24
54
|
}
|
package/src/validation.test.ts
CHANGED
|
@@ -50,6 +50,7 @@ describe("ValidationRule", () => {
|
|
|
50
50
|
|
|
51
51
|
test("validate function receives entity and returns result", () => {
|
|
52
52
|
const entity: Declarable = {
|
|
53
|
+
lexicon: "test",
|
|
53
54
|
entityType: "Test",
|
|
54
55
|
[DECLARABLE_MARKER]: true,
|
|
55
56
|
};
|
|
@@ -71,6 +72,7 @@ describe("ValidationRule", () => {
|
|
|
71
72
|
describe("validate", () => {
|
|
72
73
|
test("returns empty array when no rules provided", () => {
|
|
73
74
|
const entity: Declarable = {
|
|
75
|
+
lexicon: "test",
|
|
74
76
|
entityType: "Test",
|
|
75
77
|
[DECLARABLE_MARKER]: true,
|
|
76
78
|
};
|
|
@@ -81,6 +83,7 @@ describe("validate", () => {
|
|
|
81
83
|
|
|
82
84
|
test("applies single rule and returns result", () => {
|
|
83
85
|
const entity: Declarable = {
|
|
86
|
+
lexicon: "test",
|
|
84
87
|
entityType: "Test",
|
|
85
88
|
[DECLARABLE_MARKER]: true,
|
|
86
89
|
};
|
|
@@ -98,6 +101,7 @@ describe("validate", () => {
|
|
|
98
101
|
|
|
99
102
|
test("applies multiple rules and returns all results", () => {
|
|
100
103
|
const entity: Declarable = {
|
|
104
|
+
lexicon: "test",
|
|
101
105
|
entityType: "Test",
|
|
102
106
|
[DECLARABLE_MARKER]: true,
|
|
103
107
|
};
|
|
@@ -130,6 +134,7 @@ describe("validate", () => {
|
|
|
130
134
|
|
|
131
135
|
test("is non-blocking - does not throw on validation failure", () => {
|
|
132
136
|
const entity: Declarable = {
|
|
137
|
+
lexicon: "test",
|
|
133
138
|
entityType: "Test",
|
|
134
139
|
[DECLARABLE_MARKER]: true,
|
|
135
140
|
};
|
|
@@ -149,6 +154,7 @@ describe("validate", () => {
|
|
|
149
154
|
|
|
150
155
|
test("passes entity to each rule", () => {
|
|
151
156
|
const entity: Declarable & { name: string } = {
|
|
157
|
+
lexicon: "test",
|
|
152
158
|
entityType: "Test",
|
|
153
159
|
[DECLARABLE_MARKER]: true,
|
|
154
160
|
name: "MyEntity",
|
|
@@ -172,6 +178,7 @@ describe("validate", () => {
|
|
|
172
178
|
|
|
173
179
|
test("preserves rule execution order", () => {
|
|
174
180
|
const entity: Declarable = {
|
|
181
|
+
lexicon: "test",
|
|
175
182
|
entityType: "Test",
|
|
176
183
|
[DECLARABLE_MARKER]: true,
|
|
177
184
|
};
|
|
@@ -211,6 +218,7 @@ describe("validate", () => {
|
|
|
211
218
|
|
|
212
219
|
test("handles rules with context in results", () => {
|
|
213
220
|
const entity: Declarable & { count: number } = {
|
|
221
|
+
lexicon: "test",
|
|
214
222
|
entityType: "Test",
|
|
215
223
|
[DECLARABLE_MARKER]: true,
|
|
216
224
|
count: 5,
|
|
@@ -240,6 +248,7 @@ describe("validate", () => {
|
|
|
240
248
|
|
|
241
249
|
test("handles entity type validation", () => {
|
|
242
250
|
const entity: Declarable = {
|
|
251
|
+
lexicon: "test",
|
|
243
252
|
entityType: "Bucket",
|
|
244
253
|
[DECLARABLE_MARKER]: true,
|
|
245
254
|
};
|
|
@@ -263,6 +272,7 @@ describe("validate", () => {
|
|
|
263
272
|
|
|
264
273
|
test("validation is opt-in - only runs rules provided", () => {
|
|
265
274
|
const entity: Declarable = {
|
|
275
|
+
lexicon: "test",
|
|
266
276
|
entityType: "Test",
|
|
267
277
|
[DECLARABLE_MARKER]: true,
|
|
268
278
|
};
|
|
@@ -274,6 +284,7 @@ describe("validate", () => {
|
|
|
274
284
|
|
|
275
285
|
test("returns results in same order as rules", () => {
|
|
276
286
|
const entity: Declarable = {
|
|
287
|
+
lexicon: "test",
|
|
277
288
|
entityType: "Test",
|
|
278
289
|
[DECLARABLE_MARKER]: true,
|
|
279
290
|
};
|
|
File without changes
|
|
File without changes
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Coverage analysis for the fixture lexicon.
|
|
3
|
-
*
|
|
4
|
-
* TODO: Implement coverage analysis that checks how much of the
|
|
5
|
-
* upstream spec is covered by the generated types.
|
|
6
|
-
*/
|
|
7
|
-
export async function analyzeCoverage(options?: { verbose?: boolean }): Promise<void> {
|
|
8
|
-
console.error("Coverage analysis not yet implemented");
|
|
9
|
-
// TODO: Read generated lexicon JSON, compare against upstream spec,
|
|
10
|
-
// and report coverage metrics.
|
|
11
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { TypeScriptGenerator } from "@intentius/chant/import/generator";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* TypeScript generator for converting imported fixture templates.
|
|
5
|
-
*
|
|
6
|
-
* TODO: Implement the TypeScriptGenerator interface for your format.
|
|
7
|
-
*/
|
|
8
|
-
// export class FixtureGenerator implements TypeScriptGenerator {
|
|
9
|
-
// generate(ir: IR): string { ... }
|
|
10
|
-
// }
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { TemplateParser } from "@intentius/chant/import/parser";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Template parser for importing external fixture templates.
|
|
5
|
-
*
|
|
6
|
-
* TODO: Implement the TemplateParser interface for your format.
|
|
7
|
-
*/
|
|
8
|
-
// export class FixtureParser implements TemplateParser {
|
|
9
|
-
// parse(data: unknown): IR { ... }
|
|
10
|
-
// }
|
|
File without changes
|