@intentius/chant 0.0.18 → 0.0.24
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/templates/codegen.ts +188 -0
- package/src/cli/commands/init-lexicon/templates/docs.ts +81 -0
- package/src/cli/commands/init-lexicon/templates/examples.ts +35 -0
- package/src/cli/commands/init-lexicon/templates/lint.ts +30 -0
- package/src/cli/commands/init-lexicon/templates/lsp.ts +39 -0
- package/src/cli/commands/init-lexicon/templates/plugin.ts +110 -0
- package/src/cli/commands/init-lexicon/templates/project.ts +182 -0
- package/src/cli/commands/init-lexicon/templates/spec.ts +57 -0
- package/src/cli/commands/init-lexicon/templates/tests.ts +70 -0
- package/src/cli/commands/init-lexicon.test.ts +0 -9
- package/src/cli/commands/init-lexicon.ts +12 -868
- package/src/cli/commands/init.ts +2 -20
- package/src/cli/conflict-check.test.ts +43 -0
- 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/resource-handlers.ts +227 -0
- package/src/cli/mcp/server.test.ts +13 -9
- package/src/cli/mcp/server.ts +24 -199
- package/src/cli/mcp/state-tools.ts +138 -0
- package/src/cli/mcp/tools/build.ts +2 -1
- package/src/cli/mcp/types.ts +45 -0
- 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-file-markers.ts +69 -0
- package/src/codegen/docs-rule-scanning.ts +159 -0
- package/src/codegen/docs-sections.ts +159 -0
- package/src/codegen/docs-sidebar.ts +56 -0
- package/src/codegen/docs-types.ts +79 -0
- package/src/codegen/docs.ts +9 -495
- package/src/composite.test.ts +76 -1
- package/src/composite.ts +37 -0
- package/src/config.ts +4 -0
- package/src/declarable.test.ts +2 -1
- package/src/declarable.ts +1 -1
- package/src/discovery/collect.test.ts +34 -0
- package/src/discovery/collect.ts +12 -0
- 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-plugin-helpers.ts +130 -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/toml-emit.ts +182 -0
- package/src/toml-parse.ts +370 -0
- package/src/toml-utils.ts +60 -0
- package/src/toml.ts +5 -602
- 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
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project-level template generators for init-lexicon scaffold.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export function generatePackageJson(name: string, names: { packageName: string }): string {
|
|
6
|
+
const pkg = {
|
|
7
|
+
name: names.packageName,
|
|
8
|
+
version: "0.0.1",
|
|
9
|
+
type: "module",
|
|
10
|
+
private: true,
|
|
11
|
+
files: ["src/", "dist/"],
|
|
12
|
+
exports: {
|
|
13
|
+
".": "./src/index.ts",
|
|
14
|
+
"./*": "./src/*",
|
|
15
|
+
"./manifest": "./dist/manifest.json",
|
|
16
|
+
"./meta": "./dist/meta.json",
|
|
17
|
+
"./types": "./dist/types/index.d.ts",
|
|
18
|
+
},
|
|
19
|
+
scripts: {
|
|
20
|
+
generate: "bun run src/codegen/generate-cli.ts",
|
|
21
|
+
validate: "bun run src/validate-cli.ts",
|
|
22
|
+
docs: "bun src/codegen/docs-cli.ts",
|
|
23
|
+
prepack: "bun run generate && bun run validate",
|
|
24
|
+
},
|
|
25
|
+
dependencies: {
|
|
26
|
+
"@intentius/chant": "workspace:*",
|
|
27
|
+
},
|
|
28
|
+
devDependencies: {
|
|
29
|
+
typescript: "^5.9.3",
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return JSON.stringify(pkg, null, 2) + "\n";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function generateTsConfig(): string {
|
|
37
|
+
const config = {
|
|
38
|
+
extends: "../../tsconfig.json",
|
|
39
|
+
compilerOptions: {
|
|
40
|
+
rootDir: "./src",
|
|
41
|
+
outDir: "./dist",
|
|
42
|
+
},
|
|
43
|
+
include: ["src/**/*"],
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return JSON.stringify(config, null, 2) + "\n";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function generateJustfile(name: string): string {
|
|
50
|
+
return `# Default recipe - list all available commands
|
|
51
|
+
default:
|
|
52
|
+
@just --list
|
|
53
|
+
|
|
54
|
+
# Generate types and metadata from upstream schemas
|
|
55
|
+
generate:
|
|
56
|
+
bun run src/codegen/generate-cli.ts
|
|
57
|
+
|
|
58
|
+
# Validate generated artifacts
|
|
59
|
+
validate:
|
|
60
|
+
bun run src/validate-cli.ts
|
|
61
|
+
|
|
62
|
+
# Generate docs site, install deps, and start dev server
|
|
63
|
+
docs:
|
|
64
|
+
bun run src/codegen/docs-cli.ts
|
|
65
|
+
bun install --cwd docs
|
|
66
|
+
bun --cwd docs dev
|
|
67
|
+
|
|
68
|
+
# Build docs site for production
|
|
69
|
+
docs-build:
|
|
70
|
+
bun run src/codegen/docs-cli.ts
|
|
71
|
+
bun install --cwd docs
|
|
72
|
+
bun --cwd docs build
|
|
73
|
+
|
|
74
|
+
# Package the lexicon (generate + validate)
|
|
75
|
+
package: generate validate
|
|
76
|
+
`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function generateGitignore(): string {
|
|
80
|
+
return `dist/
|
|
81
|
+
node_modules/
|
|
82
|
+
.cache/
|
|
83
|
+
`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function generateReadme(name: string, names: { packageName: string }): string {
|
|
87
|
+
return `# ${names.packageName}
|
|
88
|
+
|
|
89
|
+
${name} lexicon plugin for [chant](https://github.com/intentius/chant).
|
|
90
|
+
|
|
91
|
+
## Getting started
|
|
92
|
+
|
|
93
|
+
\`\`\`bash
|
|
94
|
+
# Generate types from upstream spec
|
|
95
|
+
just generate
|
|
96
|
+
|
|
97
|
+
# Validate generated artifacts
|
|
98
|
+
just validate
|
|
99
|
+
|
|
100
|
+
# Generate documentation
|
|
101
|
+
just docs
|
|
102
|
+
\`\`\`
|
|
103
|
+
|
|
104
|
+
## Project structure
|
|
105
|
+
|
|
106
|
+
- \`src/plugin.ts\` — LexiconPlugin with all lifecycle methods
|
|
107
|
+
- \`src/serializer.ts\` — Build output serializer
|
|
108
|
+
- \`src/codegen/\` — Code generation pipeline
|
|
109
|
+
- \`src/spec/\` — Upstream schema fetching and parsing
|
|
110
|
+
- \`src/lint/rules/\` — Lint rules
|
|
111
|
+
- \`src/lsp/\` — LSP completions and hover
|
|
112
|
+
- \`src/generated/\` — Generated artifacts (do not edit)
|
|
113
|
+
`;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function generateSerializerTs(name: string, names: { serializerVarName: string; rulePrefix: string }): string {
|
|
117
|
+
return `import type { Serializer, Declarable } from "@intentius/chant";
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* ${name} serializer — produces minimal JSON output.
|
|
121
|
+
*
|
|
122
|
+
* TODO: Replace with your lexicon's output format.
|
|
123
|
+
*/
|
|
124
|
+
export const ${names.serializerVarName}: Serializer = {
|
|
125
|
+
name: "${name}",
|
|
126
|
+
rulePrefix: "${names.rulePrefix}",
|
|
127
|
+
|
|
128
|
+
serialize(entities: Map<string, Declarable>): string {
|
|
129
|
+
const resources: Record<string, unknown> = {};
|
|
130
|
+
|
|
131
|
+
for (const [entityName, entity] of entities) {
|
|
132
|
+
resources[entityName] = {
|
|
133
|
+
type: entity.entityType,
|
|
134
|
+
// TODO: Convert entity properties to your output format
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return JSON.stringify({ resources }, null, 2);
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
`;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function generateValidateTs(name: string): string {
|
|
145
|
+
return `/**
|
|
146
|
+
* Validate generated lexicon-${name} artifacts.
|
|
147
|
+
*
|
|
148
|
+
* Thin wrapper around the core validation framework
|
|
149
|
+
* with ${name}-specific configuration.
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
import { dirname } from "path";
|
|
153
|
+
import { fileURLToPath } from "url";
|
|
154
|
+
import { validateLexiconArtifacts, type ValidateResult } from "@intentius/chant/codegen/validate";
|
|
155
|
+
|
|
156
|
+
export type { ValidateCheck, ValidateResult } from "@intentius/chant/codegen/validate";
|
|
157
|
+
|
|
158
|
+
// TODO: Add names of required entities for your lexicon
|
|
159
|
+
const REQUIRED_NAMES: string[] = [];
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Validate the generated lexicon-${name} artifacts.
|
|
163
|
+
*/
|
|
164
|
+
export async function validate(opts?: { basePath?: string }): Promise<ValidateResult> {
|
|
165
|
+
const basePath = opts?.basePath ?? dirname(dirname(fileURLToPath(import.meta.url)));
|
|
166
|
+
|
|
167
|
+
return validateLexiconArtifacts({
|
|
168
|
+
lexiconJsonFilename: "lexicon-${name}.json",
|
|
169
|
+
requiredNames: REQUIRED_NAMES,
|
|
170
|
+
basePath,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
`;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function generateValidateCliTs(): string {
|
|
177
|
+
return `#!/usr/bin/env bun
|
|
178
|
+
import { validate } from "./validate";
|
|
179
|
+
|
|
180
|
+
await validate({ verbose: true });
|
|
181
|
+
`;
|
|
182
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec template generators for init-lexicon scaffold.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export function generateSpecFetchTs(): string {
|
|
6
|
+
return `import { fetchWithCache, extractFromZip } from "@intentius/chant/codegen/fetch";
|
|
7
|
+
|
|
8
|
+
// TODO: Set this to your upstream schema source URL
|
|
9
|
+
const SCHEMA_URL = "https://example.com/schemas.zip";
|
|
10
|
+
const CACHE_FILE = ".cache/schemas.zip";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Fetch upstream schemas with caching.
|
|
14
|
+
*
|
|
15
|
+
* TODO: Point SCHEMA_URL at your real upstream schema source.
|
|
16
|
+
*/
|
|
17
|
+
export async function fetchSchemas(options?: { force?: boolean }): Promise<Map<string, string>> {
|
|
18
|
+
const zipData = await fetchWithCache({
|
|
19
|
+
url: SCHEMA_URL,
|
|
20
|
+
cacheFile: CACHE_FILE,
|
|
21
|
+
force: options?.force,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// TODO: Adjust the filter to match your schema file names
|
|
25
|
+
return extractFromZip(zipData, (name) => name.endsWith(".json"));
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function generateSpecParseTs(): string {
|
|
31
|
+
return `/**
|
|
32
|
+
* Parsed schema result for a single schema file.
|
|
33
|
+
*/
|
|
34
|
+
export interface ParseResult {
|
|
35
|
+
typeName: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
properties: Map<string, ParsedProperty>;
|
|
38
|
+
attributes: string[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ParsedProperty {
|
|
42
|
+
name: string;
|
|
43
|
+
type: string;
|
|
44
|
+
required: boolean;
|
|
45
|
+
description?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Parse a single schema file into a ParseResult.
|
|
50
|
+
*
|
|
51
|
+
* TODO: Implement parsing for your schema format.
|
|
52
|
+
*/
|
|
53
|
+
export function parseSchema(name: string, content: string): ParseResult {
|
|
54
|
+
throw new Error(\`TODO: implement parseSchema for \${name}\`);
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
57
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test file template generators for init-lexicon scaffold.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export function generatePluginTestTs(name: string, names: { pluginVarName: string }): string {
|
|
6
|
+
return `import { describe, expect, it } from "bun:test";
|
|
7
|
+
import { ${names.pluginVarName} } from "./plugin";
|
|
8
|
+
import { isLexiconPlugin } from "@intentius/chant/lexicon";
|
|
9
|
+
|
|
10
|
+
describe("${name} plugin", () => {
|
|
11
|
+
it("is a valid LexiconPlugin", () => {
|
|
12
|
+
expect(isLexiconPlugin(${names.pluginVarName})).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("has the correct name", () => {
|
|
16
|
+
expect(${names.pluginVarName}.name).toBe("${name}");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("has a serializer", () => {
|
|
20
|
+
expect(${names.pluginVarName}.serializer).toBeDefined();
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function generateSerializerTestTs(name: string, names: { serializerVarName: string }): string {
|
|
27
|
+
return `import { describe, expect, it } from "bun:test";
|
|
28
|
+
import { ${names.serializerVarName} } from "./serializer";
|
|
29
|
+
|
|
30
|
+
describe("${name} serializer", () => {
|
|
31
|
+
it("serializes an empty map to valid JSON", () => {
|
|
32
|
+
const result = ${names.serializerVarName}.serialize(new Map());
|
|
33
|
+
expect(typeof result).toBe("string");
|
|
34
|
+
expect(() => JSON.parse(result)).not.toThrow();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("has the correct name", () => {
|
|
38
|
+
expect(${names.serializerVarName}.name).toBe("${name}");
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function generateCompletionsTestTs(): string {
|
|
45
|
+
return `import { describe, expect, it } from "bun:test";
|
|
46
|
+
import { completions } from "./completions";
|
|
47
|
+
|
|
48
|
+
describe("LSP completions", () => {
|
|
49
|
+
it("returns an array", () => {
|
|
50
|
+
// TODO: Replace with a real CompletionContext
|
|
51
|
+
const result = completions({} as any);
|
|
52
|
+
expect(Array.isArray(result)).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function generateHoverTestTs(): string {
|
|
59
|
+
return `import { describe, expect, it } from "bun:test";
|
|
60
|
+
import { hover } from "./hover";
|
|
61
|
+
|
|
62
|
+
describe("LSP hover", () => {
|
|
63
|
+
it("returns undefined for unknown context", () => {
|
|
64
|
+
// TODO: Replace with a real HoverContext
|
|
65
|
+
const result = hover({} as any);
|
|
66
|
+
expect(result).toBeUndefined();
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
`;
|
|
70
|
+
}
|
|
@@ -51,9 +51,6 @@ describe("initLexiconCommand", () => {
|
|
|
51
51
|
"src/lsp/hover.ts",
|
|
52
52
|
"src/lsp/completions.test.ts",
|
|
53
53
|
"src/lsp/hover.test.ts",
|
|
54
|
-
"src/import/parser.ts",
|
|
55
|
-
"src/import/generator.ts",
|
|
56
|
-
"src/coverage.ts",
|
|
57
54
|
"src/validate.ts",
|
|
58
55
|
"src/validate-cli.ts",
|
|
59
56
|
"package.json",
|
|
@@ -66,15 +63,9 @@ describe("initLexiconCommand", () => {
|
|
|
66
63
|
"docs/astro.config.mjs",
|
|
67
64
|
"docs/src/content.config.ts",
|
|
68
65
|
"docs/src/content/docs/index.mdx",
|
|
69
|
-
"docs/src/content/docs/getting-started.mdx",
|
|
70
|
-
"docs/src/content/docs/serialization.mdx",
|
|
71
|
-
"docs/src/content/docs/lint-rules.mdx",
|
|
72
66
|
"examples/getting-started/package.json",
|
|
73
67
|
"examples/getting-started/src/infra.ts",
|
|
74
68
|
"src/generated/.gitkeep",
|
|
75
|
-
"src/composites/.gitkeep",
|
|
76
|
-
"src/actions/.gitkeep",
|
|
77
|
-
"src/lint/post-synth/.gitkeep",
|
|
78
69
|
];
|
|
79
70
|
|
|
80
71
|
for (const file of expectedFiles) {
|