@intentius/chant 0.0.1
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/README.md +365 -0
- package/package.json +22 -0
- package/src/attrref.test.ts +148 -0
- package/src/attrref.ts +50 -0
- package/src/barrel.test.ts +157 -0
- package/src/barrel.ts +101 -0
- package/src/bench.test.ts +227 -0
- package/src/build.test.ts +437 -0
- package/src/build.ts +425 -0
- package/src/builder.test.ts +312 -0
- package/src/builder.ts +56 -0
- package/src/child-project.ts +44 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/README.md +26 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/docs/astro.config.mjs +14 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/docs/package.json +16 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/docs/src/content/docs/index.mdx +8 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/docs/src/content.config.ts +7 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/docs/tsconfig.json +10 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/examples/getting-started/.gitkeep +0 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/justfile +26 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/package.json +29 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/codegen/docs.ts +25 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/codegen/generate-cli.ts +8 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/codegen/generate.ts +74 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/codegen/naming.ts +33 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/codegen/package.ts +25 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/codegen/rollback.ts +45 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/coverage.ts +11 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/generated/.gitkeep +0 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/import/generator.ts +10 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/import/parser.ts +10 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/index.ts +9 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/lint/rules/index.ts +1 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/lint/rules/sample.ts +18 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/lsp/completions.ts +14 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/lsp/hover.ts +14 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/plugin.ts +110 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/serializer.ts +24 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/spec/fetch.ts +21 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/spec/parse.ts +25 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/validate-cli.ts +4 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/src/validate.ts +24 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/tsconfig.json +10 -0
- package/src/cli/commands/__fixtures__/sample-rule.ts +11 -0
- package/src/cli/commands/__snapshots__/init-lexicon.test.ts.snap +222 -0
- package/src/cli/commands/build.test.ts +149 -0
- package/src/cli/commands/build.ts +344 -0
- package/src/cli/commands/diff.test.ts +148 -0
- package/src/cli/commands/diff.ts +221 -0
- package/src/cli/commands/doctor.test.ts +239 -0
- package/src/cli/commands/doctor.ts +224 -0
- package/src/cli/commands/import.test.ts +379 -0
- package/src/cli/commands/import.ts +335 -0
- package/src/cli/commands/init-lexicon.test.ts +297 -0
- package/src/cli/commands/init-lexicon.ts +993 -0
- package/src/cli/commands/init.test.ts +317 -0
- package/src/cli/commands/init.ts +505 -0
- package/src/cli/commands/licenses.ts +165 -0
- package/src/cli/commands/lint.test.ts +332 -0
- package/src/cli/commands/lint.ts +408 -0
- package/src/cli/commands/list.test.ts +100 -0
- package/src/cli/commands/list.ts +108 -0
- package/src/cli/commands/update.test.ts +38 -0
- package/src/cli/commands/update.ts +207 -0
- package/src/cli/conflict-check.test.ts +255 -0
- package/src/cli/conflict-check.ts +89 -0
- package/src/cli/debug.ts +8 -0
- package/src/cli/format.test.ts +140 -0
- package/src/cli/format.ts +133 -0
- package/src/cli/handlers/build.ts +58 -0
- package/src/cli/handlers/dev.ts +38 -0
- package/src/cli/handlers/init.ts +46 -0
- package/src/cli/handlers/lint.ts +36 -0
- package/src/cli/handlers/misc.ts +57 -0
- package/src/cli/handlers/serve.ts +26 -0
- package/src/cli/index.ts +3 -0
- package/src/cli/lsp/capabilities.ts +46 -0
- package/src/cli/lsp/diagnostics.ts +52 -0
- package/src/cli/lsp/server.test.ts +618 -0
- package/src/cli/lsp/server.ts +393 -0
- package/src/cli/main.test.ts +257 -0
- package/src/cli/main.ts +224 -0
- package/src/cli/mcp/resources/context.ts +59 -0
- package/src/cli/mcp/server.test.ts +747 -0
- package/src/cli/mcp/server.ts +402 -0
- package/src/cli/mcp/tools/build.ts +117 -0
- package/src/cli/mcp/tools/import.ts +48 -0
- package/src/cli/mcp/tools/lint.ts +45 -0
- package/src/cli/plugins.test.ts +31 -0
- package/src/cli/plugins.ts +94 -0
- package/src/cli/registry.ts +73 -0
- package/src/cli/reporters/stylish.test.ts +282 -0
- package/src/cli/reporters/stylish.ts +186 -0
- package/src/cli/watch.test.ts +81 -0
- package/src/cli/watch.ts +101 -0
- package/src/codegen/case.test.ts +30 -0
- package/src/codegen/case.ts +11 -0
- package/src/codegen/coverage.ts +167 -0
- package/src/codegen/docs.ts +634 -0
- package/src/codegen/fetch.test.ts +119 -0
- package/src/codegen/fetch.ts +261 -0
- package/src/codegen/generate-registry.test.ts +118 -0
- package/src/codegen/generate-registry.ts +107 -0
- package/src/codegen/generate-runtime-index.test.ts +81 -0
- package/src/codegen/generate-runtime-index.ts +99 -0
- package/src/codegen/generate-typescript.test.ts +146 -0
- package/src/codegen/generate-typescript.ts +161 -0
- package/src/codegen/generate.ts +206 -0
- package/src/codegen/json-patch.test.ts +113 -0
- package/src/codegen/json-patch.ts +151 -0
- package/src/codegen/json-schema.test.ts +196 -0
- package/src/codegen/json-schema.ts +209 -0
- package/src/codegen/naming.ts +201 -0
- package/src/codegen/package.ts +161 -0
- package/src/codegen/rollback.test.ts +92 -0
- package/src/codegen/rollback.ts +115 -0
- package/src/codegen/topo-sort.test.ts +69 -0
- package/src/codegen/topo-sort.ts +46 -0
- package/src/codegen/typecheck.test.ts +37 -0
- package/src/codegen/typecheck.ts +74 -0
- package/src/codegen/validate.test.ts +86 -0
- package/src/codegen/validate.ts +143 -0
- package/src/composite.test.ts +426 -0
- package/src/composite.ts +243 -0
- package/src/config.test.ts +91 -0
- package/src/config.ts +87 -0
- package/src/declarable.test.ts +160 -0
- package/src/declarable.ts +47 -0
- package/src/detectLexicon.test.ts +236 -0
- package/src/detectLexicon.ts +37 -0
- package/src/discovery/cache.test.ts +78 -0
- package/src/discovery/cache.ts +86 -0
- package/src/discovery/collect.test.ts +269 -0
- package/src/discovery/collect.ts +51 -0
- package/src/discovery/cycles.test.ts +238 -0
- package/src/discovery/cycles.ts +107 -0
- package/src/discovery/files.test.ts +154 -0
- package/src/discovery/files.ts +61 -0
- package/src/discovery/graph.test.ts +476 -0
- package/src/discovery/graph.ts +150 -0
- package/src/discovery/import.test.ts +199 -0
- package/src/discovery/import.ts +20 -0
- package/src/discovery/index.test.ts +272 -0
- package/src/discovery/index.ts +132 -0
- package/src/discovery/resolve.test.ts +267 -0
- package/src/discovery/resolve.ts +54 -0
- package/src/errors.test.ts +138 -0
- package/src/errors.ts +86 -0
- package/src/import/base-parser.test.ts +67 -0
- package/src/import/base-parser.ts +48 -0
- package/src/import/generator.ts +21 -0
- package/src/import/ir-utils.test.ts +103 -0
- package/src/import/ir-utils.ts +87 -0
- package/src/import/parser.ts +41 -0
- package/src/index.ts +60 -0
- package/src/intrinsic-interpolation.test.ts +91 -0
- package/src/intrinsic-interpolation.ts +89 -0
- package/src/intrinsic.test.ts +69 -0
- package/src/intrinsic.ts +43 -0
- package/src/lexicon-integrity.test.ts +94 -0
- package/src/lexicon-integrity.ts +69 -0
- package/src/lexicon-manifest.test.ts +101 -0
- package/src/lexicon-manifest.ts +71 -0
- package/src/lexicon-output.test.ts +182 -0
- package/src/lexicon-output.ts +82 -0
- package/src/lexicon-schema.test.ts +239 -0
- package/src/lexicon-schema.ts +144 -0
- package/src/lexicon.ts +212 -0
- package/src/lint/config-overrides.test.ts +254 -0
- package/src/lint/config.test.ts +644 -0
- package/src/lint/config.ts +375 -0
- package/src/lint/declarative.test.ts +256 -0
- package/src/lint/declarative.ts +187 -0
- package/src/lint/engine.test.ts +465 -0
- package/src/lint/engine.ts +172 -0
- package/src/lint/named-checks.test.ts +37 -0
- package/src/lint/named-checks.ts +33 -0
- package/src/lint/parser.test.ts +129 -0
- package/src/lint/parser.ts +42 -0
- package/src/lint/post-synth.test.ts +113 -0
- package/src/lint/post-synth.ts +76 -0
- package/src/lint/presets/relaxed.json +19 -0
- package/src/lint/presets/strict.json +19 -0
- package/src/lint/rule-loader.test.ts +67 -0
- package/src/lint/rule-loader.ts +67 -0
- package/src/lint/rule-options.test.ts +141 -0
- package/src/lint/rule.test.ts +196 -0
- package/src/lint/rule.ts +98 -0
- package/src/lint/rules/barrel-import-style.test.ts +80 -0
- package/src/lint/rules/barrel-import-style.ts +59 -0
- package/src/lint/rules/composite-scope.ts +55 -0
- package/src/lint/rules/cor017-composite-name-match.test.ts +107 -0
- package/src/lint/rules/cor017-composite-name-match.ts +108 -0
- package/src/lint/rules/cor018-composite-prefer-lexicon-type.test.ts +172 -0
- package/src/lint/rules/cor018-composite-prefer-lexicon-type.ts +167 -0
- package/src/lint/rules/declarable-naming-convention.test.ts +69 -0
- package/src/lint/rules/declarable-naming-convention.ts +70 -0
- package/src/lint/rules/enforce-barrel-import.test.ts +169 -0
- package/src/lint/rules/enforce-barrel-import.ts +81 -0
- package/src/lint/rules/enforce-barrel-ref.test.ts +114 -0
- package/src/lint/rules/enforce-barrel-ref.ts +75 -0
- package/src/lint/rules/evl001-non-literal-expression.test.ts +158 -0
- package/src/lint/rules/evl001-non-literal-expression.ts +149 -0
- package/src/lint/rules/evl002-control-flow-resource.test.ts +110 -0
- package/src/lint/rules/evl002-control-flow-resource.ts +61 -0
- package/src/lint/rules/evl003-dynamic-property-access.test.ts +63 -0
- package/src/lint/rules/evl003-dynamic-property-access.ts +41 -0
- package/src/lint/rules/evl004-spread-non-const.test.ts +130 -0
- package/src/lint/rules/evl004-spread-non-const.ts +111 -0
- package/src/lint/rules/evl005-resource-block-body.test.ts +59 -0
- package/src/lint/rules/evl005-resource-block-body.ts +49 -0
- package/src/lint/rules/evl006-barrel-usage.test.ts +63 -0
- package/src/lint/rules/evl006-barrel-usage.ts +95 -0
- package/src/lint/rules/evl007-invalid-siblings.test.ts +87 -0
- package/src/lint/rules/evl007-invalid-siblings.ts +139 -0
- package/src/lint/rules/evl008-unresolvable-barrel-ref.test.ts +118 -0
- package/src/lint/rules/evl008-unresolvable-barrel-ref.ts +140 -0
- package/src/lint/rules/evl009-composite-no-constant.test.ts +162 -0
- package/src/lint/rules/evl009-composite-no-constant.ts +171 -0
- package/src/lint/rules/evl010-composite-no-transform.test.ts +121 -0
- package/src/lint/rules/evl010-composite-no-transform.ts +69 -0
- package/src/lint/rules/export-required.test.ts +213 -0
- package/src/lint/rules/export-required.ts +158 -0
- package/src/lint/rules/file-declarable-limit.test.ts +148 -0
- package/src/lint/rules/file-declarable-limit.ts +96 -0
- package/src/lint/rules/flat-declarations.test.ts +210 -0
- package/src/lint/rules/flat-declarations.ts +70 -0
- package/src/lint/rules/index.ts +99 -0
- package/src/lint/rules/no-cyclic-declarable-ref.test.ts +135 -0
- package/src/lint/rules/no-cyclic-declarable-ref.ts +178 -0
- package/src/lint/rules/no-redundant-type-import.test.ts +129 -0
- package/src/lint/rules/no-redundant-type-import.ts +85 -0
- package/src/lint/rules/no-redundant-value-cast.test.ts +51 -0
- package/src/lint/rules/no-redundant-value-cast.ts +46 -0
- package/src/lint/rules/no-string-ref.test.ts +100 -0
- package/src/lint/rules/no-string-ref.ts +66 -0
- package/src/lint/rules/no-unused-declarable-import.test.ts +74 -0
- package/src/lint/rules/no-unused-declarable-import.ts +103 -0
- package/src/lint/rules/no-unused-declarable.test.ts +134 -0
- package/src/lint/rules/no-unused-declarable.ts +118 -0
- package/src/lint/rules/prefer-namespace-import.test.ts +102 -0
- package/src/lint/rules/prefer-namespace-import.ts +63 -0
- package/src/lint/rules/single-concern-file.test.ts +156 -0
- package/src/lint/rules/single-concern-file.ts +98 -0
- package/src/lint/rules/stale-barrel-types.ts +60 -0
- package/src/lint/selectors.test.ts +113 -0
- package/src/lint/selectors.ts +188 -0
- package/src/lsp/lexicon-providers.ts +191 -0
- package/src/lsp/types.ts +79 -0
- package/src/mcp/types.ts +22 -0
- package/src/project/scan.test.ts +178 -0
- package/src/project/scan.ts +182 -0
- package/src/project/sync.test.ts +87 -0
- package/src/project/sync.ts +46 -0
- package/src/project-validation.test.ts +64 -0
- package/src/project-validation.ts +79 -0
- package/src/pseudo-parameter.test.ts +39 -0
- package/src/pseudo-parameter.ts +47 -0
- package/src/runtime.ts +68 -0
- package/src/serializer-walker.test.ts +124 -0
- package/src/serializer-walker.ts +83 -0
- package/src/serializer.ts +42 -0
- package/src/sort.test.ts +290 -0
- package/src/sort.ts +58 -0
- package/src/stack-output.ts +82 -0
- package/src/types.test.ts +307 -0
- package/src/types.ts +46 -0
- package/src/utils.test.ts +195 -0
- package/src/utils.ts +46 -0
- package/src/validation.test.ts +308 -0
- package/src/validation.ts +50 -0
package/src/cli/main.ts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { formatSuccess, formatError } from "./format";
|
|
5
|
+
import { loadPlugins, resolveProjectLexicons } from "./plugins";
|
|
6
|
+
import { resolveCommand, type CommandDef, type ParsedArgs } from "./registry";
|
|
7
|
+
import { runBuild } from "./handlers/build";
|
|
8
|
+
import { runLint } from "./handlers/lint";
|
|
9
|
+
import { runDevGenerate, runDevPublish, runDevRollback, runDevUnknown } from "./handlers/dev";
|
|
10
|
+
import { runServeLsp, runServeMcp, runServeUnknown } from "./handlers/serve";
|
|
11
|
+
import { runInit, runInitLexicon } from "./handlers/init";
|
|
12
|
+
import { runList, runImport, runUpdate, runDoctor } from "./handlers/misc";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Parse command line arguments
|
|
16
|
+
*/
|
|
17
|
+
export function parseArgs(args: string[]): ParsedArgs {
|
|
18
|
+
const result: ParsedArgs = {
|
|
19
|
+
command: "",
|
|
20
|
+
path: ".",
|
|
21
|
+
extraPositional: undefined,
|
|
22
|
+
extraPositional2: undefined,
|
|
23
|
+
output: undefined,
|
|
24
|
+
format: "",
|
|
25
|
+
force: undefined,
|
|
26
|
+
fix: false,
|
|
27
|
+
lexicon: undefined,
|
|
28
|
+
watch: false,
|
|
29
|
+
verbose: false,
|
|
30
|
+
help: false,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
let i = 0;
|
|
34
|
+
while (i < args.length) {
|
|
35
|
+
const arg = args[i];
|
|
36
|
+
|
|
37
|
+
if (arg === "--help" || arg === "-h") {
|
|
38
|
+
result.help = true;
|
|
39
|
+
} else if (arg === "--output" || arg === "-o") {
|
|
40
|
+
result.output = args[++i];
|
|
41
|
+
} else if (arg === "--format" || arg === "-f") {
|
|
42
|
+
result.format = args[++i];
|
|
43
|
+
} else if (arg === "--lexicon" || arg === "-d") {
|
|
44
|
+
result.lexicon = args[++i];
|
|
45
|
+
} else if (arg === "--force") {
|
|
46
|
+
result.force = true;
|
|
47
|
+
} else if (arg === "--fix") {
|
|
48
|
+
result.fix = true;
|
|
49
|
+
} else if (arg === "--watch" || arg === "-w") {
|
|
50
|
+
result.watch = true;
|
|
51
|
+
} else if (arg === "--verbose" || arg === "-v") {
|
|
52
|
+
result.verbose = true;
|
|
53
|
+
} else if (!arg.startsWith("-")) {
|
|
54
|
+
if (!result.command) {
|
|
55
|
+
result.command = arg;
|
|
56
|
+
} else if (result.path === ".") {
|
|
57
|
+
result.path = arg;
|
|
58
|
+
} else if (!result.extraPositional) {
|
|
59
|
+
result.extraPositional = arg;
|
|
60
|
+
} else {
|
|
61
|
+
result.extraPositional2 = arg;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
i++;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Print help message
|
|
73
|
+
*/
|
|
74
|
+
function printHelp(): void {
|
|
75
|
+
console.log(`
|
|
76
|
+
chant - Declarative infrastructure specification toolkit
|
|
77
|
+
|
|
78
|
+
Usage:
|
|
79
|
+
chant <command> [options] [path]
|
|
80
|
+
|
|
81
|
+
Commands:
|
|
82
|
+
init Initialize a new chant project
|
|
83
|
+
init lexicon <name> Scaffold a new lexicon plugin project
|
|
84
|
+
build Build infrastructure from specification files
|
|
85
|
+
lint Check specifications for issues
|
|
86
|
+
list List discovered entities
|
|
87
|
+
import Import external template into TypeScript
|
|
88
|
+
|
|
89
|
+
Lexicon development:
|
|
90
|
+
dev generate Generate lexicon artifacts (+ validate + coverage)
|
|
91
|
+
dev publish Package lexicon for distribution
|
|
92
|
+
dev rollback List or restore generation snapshots
|
|
93
|
+
|
|
94
|
+
Servers:
|
|
95
|
+
serve lsp Start the LSP server (stdio)
|
|
96
|
+
serve mcp Start the MCP server (stdio)
|
|
97
|
+
|
|
98
|
+
Project:
|
|
99
|
+
update Sync lexicon types into .chant/types/
|
|
100
|
+
doctor Check project health and configuration
|
|
101
|
+
|
|
102
|
+
Options:
|
|
103
|
+
-o, --output <file> Write output to file instead of stdout
|
|
104
|
+
-f, --format <fmt> Output format (command-specific):
|
|
105
|
+
- build: json (default) or yaml
|
|
106
|
+
- list: text (default) or json
|
|
107
|
+
- lint: stylish (default), json, or sarif
|
|
108
|
+
-d, --lexicon <name> Build only the specified lexicon (e.g. aws, gitlab)
|
|
109
|
+
--fix Auto-fix fixable issues (lint command)
|
|
110
|
+
--force Force overwrite existing files (import command)
|
|
111
|
+
-w, --watch Watch for changes and rebuild/re-lint (build, lint)
|
|
112
|
+
-v, --verbose Show stack traces on errors
|
|
113
|
+
-h, --help Show this help message
|
|
114
|
+
|
|
115
|
+
Examples:
|
|
116
|
+
chant build ./infra/
|
|
117
|
+
chant build ./infra/ --output stack.json
|
|
118
|
+
chant build ./infra/ --format yaml
|
|
119
|
+
chant build ./infra/ --watch
|
|
120
|
+
chant import template.json --output ./infra/
|
|
121
|
+
chant lint ./infra/
|
|
122
|
+
chant lint ./infra/ --format sarif
|
|
123
|
+
chant lint ./infra/ --watch
|
|
124
|
+
chant list ./infra/
|
|
125
|
+
chant list ./infra/ --format json
|
|
126
|
+
`);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Load lexicon plugins for the given project path, or exit with an error.
|
|
131
|
+
*/
|
|
132
|
+
async function loadPluginsOrExit(path: string): Promise<import("../lexicon").LexiconPlugin[]> {
|
|
133
|
+
let plugins;
|
|
134
|
+
try {
|
|
135
|
+
const lexiconNames = await resolveProjectLexicons(resolve(path));
|
|
136
|
+
plugins = await loadPlugins(lexiconNames);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
139
|
+
console.error(formatError({ message: errorMessage }));
|
|
140
|
+
process.exit(1);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (plugins.length === 0) {
|
|
144
|
+
console.error(formatError({
|
|
145
|
+
message: "No lexicon detected",
|
|
146
|
+
hint: 'Run "chant init --lexicon <name>" to initialize a project, or add a lexicon to chant.config.ts',
|
|
147
|
+
}));
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return plugins;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ── Command registry ──────────────────────────────────────────────
|
|
155
|
+
|
|
156
|
+
const registry: CommandDef[] = [
|
|
157
|
+
// Primary commands
|
|
158
|
+
{ name: "build", requiresPlugins: true, handler: runBuild },
|
|
159
|
+
{ name: "lint", handler: runLint },
|
|
160
|
+
{ name: "list", handler: runList },
|
|
161
|
+
{ name: "import", handler: runImport },
|
|
162
|
+
{ name: "init", handler: runInit },
|
|
163
|
+
{ name: "init lexicon", handler: runInitLexicon },
|
|
164
|
+
{ name: "update", handler: runUpdate },
|
|
165
|
+
{ name: "doctor", handler: runDoctor },
|
|
166
|
+
|
|
167
|
+
// Dev subcommands
|
|
168
|
+
{ name: "dev generate", requiresPlugins: true, handler: runDevGenerate },
|
|
169
|
+
{ name: "dev publish", requiresPlugins: true, handler: runDevPublish },
|
|
170
|
+
{ name: "dev rollback", requiresPlugins: true, handler: runDevRollback },
|
|
171
|
+
|
|
172
|
+
// Serve subcommands
|
|
173
|
+
{ name: "serve lsp", requiresPlugins: true, handler: runServeLsp },
|
|
174
|
+
{ name: "serve mcp", requiresPlugins: true, handler: runServeMcp },
|
|
175
|
+
|
|
176
|
+
// Fallback for unknown subcommands (must come after compound entries)
|
|
177
|
+
{ name: "dev", handler: runDevUnknown },
|
|
178
|
+
{ name: "serve", handler: runServeUnknown },
|
|
179
|
+
];
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Main entry point
|
|
183
|
+
*/
|
|
184
|
+
async function main(): Promise<void> {
|
|
185
|
+
const args = parseArgs(process.argv.slice(2));
|
|
186
|
+
|
|
187
|
+
if (args.help || !args.command) {
|
|
188
|
+
printHelp();
|
|
189
|
+
process.exit(args.help ? 0 : 1);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const match = resolveCommand(args, registry);
|
|
193
|
+
if (!match) {
|
|
194
|
+
console.error(formatError({
|
|
195
|
+
message: `Unknown command: ${args.command}`,
|
|
196
|
+
hint: 'Run "chant --help" to see available commands',
|
|
197
|
+
}));
|
|
198
|
+
process.exit(1);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// For compound commands (e.g. "dev generate"), args.path is the subcommand,
|
|
202
|
+
// so the project path shifts to extraPositional. For simple commands, use args.path.
|
|
203
|
+
const projectPath = match.compound ? (args.extraPositional ?? ".") : args.path;
|
|
204
|
+
const plugins = match.def.requiresPlugins
|
|
205
|
+
? await loadPluginsOrExit(projectPath)
|
|
206
|
+
: [];
|
|
207
|
+
const serializers = plugins.map((p) => p.serializer);
|
|
208
|
+
const ctx = { args, plugins, serializers };
|
|
209
|
+
|
|
210
|
+
process.exit(await match.def.handler(ctx));
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Only run main when executed directly, not when imported
|
|
214
|
+
if (import.meta.main) {
|
|
215
|
+
main().catch((err) => {
|
|
216
|
+
const verbose = process.argv.includes("--verbose") || process.argv.includes("-v");
|
|
217
|
+
if (verbose && err instanceof Error && err.stack) {
|
|
218
|
+
console.error(err.stack);
|
|
219
|
+
} else {
|
|
220
|
+
console.error(formatError({ message: err instanceof Error ? err.message : String(err) }));
|
|
221
|
+
}
|
|
222
|
+
process.exit(1);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the chant context for MCP
|
|
3
|
+
* Returns lexicon-specific instructions and patterns
|
|
4
|
+
*/
|
|
5
|
+
export function getContext(): string {
|
|
6
|
+
return `# chant Development Context
|
|
7
|
+
|
|
8
|
+
chant is a lexicon-agnostic declarative specification system for infrastructure as code.
|
|
9
|
+
|
|
10
|
+
## Key Concepts
|
|
11
|
+
|
|
12
|
+
### Declarable
|
|
13
|
+
Base interface for all infrastructure entities. Every resource you create must implement \`Declarable\`.
|
|
14
|
+
|
|
15
|
+
### Lexicon
|
|
16
|
+
Lexicons define target platforms (e.g. AWS). Each lexicon:
|
|
17
|
+
- Has a unique name and rule prefix
|
|
18
|
+
- Implements \`serialize(entities)\` to generate platform-specific output
|
|
19
|
+
|
|
20
|
+
### AttrRef
|
|
21
|
+
Deferred references to entity attributes. Use these for cross-resource references:
|
|
22
|
+
\`\`\`typescript
|
|
23
|
+
const bucket = new Bucket({ name: "data" });
|
|
24
|
+
// bucket.arn is an AttrRef that resolves at build time
|
|
25
|
+
\`\`\`
|
|
26
|
+
|
|
27
|
+
### Intrinsics
|
|
28
|
+
Lexicon-provided functions resolved at build time:
|
|
29
|
+
- \`Sub\` - String interpolation with references
|
|
30
|
+
- \`Ref\` - Reference to another resource
|
|
31
|
+
- \`Json\` - JSON serialization
|
|
32
|
+
|
|
33
|
+
## CLI Commands
|
|
34
|
+
|
|
35
|
+
### Build
|
|
36
|
+
\`\`\`bash
|
|
37
|
+
chant build ./infra/ # Build infrastructure
|
|
38
|
+
chant build ./infra/ -o out.json # Output to file
|
|
39
|
+
\`\`\`
|
|
40
|
+
|
|
41
|
+
### Lint
|
|
42
|
+
\`\`\`bash
|
|
43
|
+
chant lint ./infra/ # Check for issues
|
|
44
|
+
\`\`\`
|
|
45
|
+
|
|
46
|
+
### Import
|
|
47
|
+
\`\`\`bash
|
|
48
|
+
chant import template.json # Convert external template
|
|
49
|
+
chant import template.json -o ./src/ # Custom output dir
|
|
50
|
+
\`\`\`
|
|
51
|
+
|
|
52
|
+
## Best Practices
|
|
53
|
+
|
|
54
|
+
1. **Flat Declarations**: Keep declarations at module level, avoid deep nesting
|
|
55
|
+
2. **Use AttrRefs**: Reference other resources via AttrRef, not string interpolation
|
|
56
|
+
3. **Lexicon-specific Rules**: Each lexicon has lint rules (WAW001, etc.)
|
|
57
|
+
4. **Type Safety**: Leverage TypeScript for infrastructure definitions
|
|
58
|
+
`;
|
|
59
|
+
}
|