@intentius/chant 0.0.5 → 0.0.8

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 (38) hide show
  1. package/bin/chant +20 -0
  2. package/package.json +18 -17
  3. package/src/cli/commands/__fixtures__/init-lexicon-output/src/plugin.ts +0 -25
  4. package/src/cli/commands/__snapshots__/init-lexicon.test.ts.snap +0 -25
  5. package/src/cli/commands/build.ts +1 -2
  6. package/src/cli/commands/import.ts +2 -2
  7. package/src/cli/commands/init-lexicon.test.ts +0 -3
  8. package/src/cli/commands/init-lexicon.ts +1 -79
  9. package/src/cli/commands/init.ts +14 -3
  10. package/src/cli/commands/list.ts +2 -2
  11. package/src/cli/commands/update.ts +5 -3
  12. package/src/cli/conflict-check.test.ts +0 -1
  13. package/src/cli/handlers/dev.ts +1 -9
  14. package/src/cli/main.ts +13 -3
  15. package/src/cli/mcp/server.test.ts +207 -4
  16. package/src/cli/mcp/server.ts +6 -0
  17. package/src/cli/mcp/tools/explain.ts +134 -0
  18. package/src/cli/mcp/tools/scaffold.ts +107 -0
  19. package/src/cli/mcp/tools/search.ts +98 -0
  20. package/src/codegen/generate-registry.test.ts +1 -1
  21. package/src/codegen/generate-registry.ts +2 -3
  22. package/src/codegen/generate-typescript.test.ts +6 -6
  23. package/src/codegen/generate-typescript.ts +2 -6
  24. package/src/codegen/generate.ts +1 -12
  25. package/src/codegen/typecheck.ts +6 -11
  26. package/src/config.ts +4 -0
  27. package/src/index.ts +1 -1
  28. package/src/lexicon-integrity.ts +5 -4
  29. package/src/lexicon.ts +2 -6
  30. package/src/lint/config.ts +8 -6
  31. package/src/runtime-adapter.ts +158 -0
  32. package/src/serializer-walker.test.ts +0 -9
  33. package/src/serializer-walker.ts +1 -3
  34. package/src/cli/commands/__fixtures__/init-lexicon-output/src/codegen/rollback.ts +0 -45
  35. package/src/codegen/case.test.ts +0 -30
  36. package/src/codegen/case.ts +0 -11
  37. package/src/codegen/rollback.test.ts +0 -92
  38. package/src/codegen/rollback.ts +0 -115
@@ -1,115 +0,0 @@
1
- /**
2
- * Artifact snapshot and restore for generation rollback.
3
- */
4
- import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync } from "fs";
5
- import { join } from "path";
6
- import { hashArtifact } from "../lexicon-integrity";
7
-
8
- export interface ArtifactSnapshot {
9
- timestamp: string;
10
- files: Record<string, string>;
11
- hashes: Record<string, string>;
12
- resourceCount: number;
13
- }
14
-
15
- export interface SnapshotInfo {
16
- path: string;
17
- timestamp: string;
18
- resourceCount: number;
19
- }
20
-
21
- const DEFAULT_ARTIFACT_NAMES = ["lexicon.json", "index.d.ts", "index.ts"];
22
-
23
- /**
24
- * Snapshot current generated artifacts.
25
- *
26
- * @param generatedDir - Directory containing generated artifacts
27
- * @param artifactNames - List of filenames to snapshot (defaults to generic names)
28
- */
29
- export function snapshotArtifacts(
30
- generatedDir: string,
31
- artifactNames: string[] = DEFAULT_ARTIFACT_NAMES,
32
- ): ArtifactSnapshot {
33
- const files: Record<string, string> = {};
34
- const hashes: Record<string, string> = {};
35
- let resourceCount = 0;
36
-
37
- for (const entry of artifactNames) {
38
- const path = join(generatedDir, entry);
39
- if (existsSync(path)) {
40
- const content = readFileSync(path, "utf-8");
41
- files[entry] = content;
42
- hashes[entry] = hashArtifact(content);
43
-
44
- // Count resources in any .json artifact
45
- if (entry.endsWith(".json")) {
46
- try {
47
- const parsed = JSON.parse(content);
48
- resourceCount = Object.values(parsed).filter(
49
- (e: any) => e && typeof e === "object" && e.kind === "resource"
50
- ).length;
51
- } catch {}
52
- }
53
- }
54
- }
55
-
56
- return {
57
- timestamp: new Date().toISOString(),
58
- files,
59
- hashes,
60
- resourceCount,
61
- };
62
- }
63
-
64
- /**
65
- * Save a snapshot to the .snapshots directory.
66
- */
67
- export function saveSnapshot(snapshot: ArtifactSnapshot, snapshotsDir: string): string {
68
- mkdirSync(snapshotsDir, { recursive: true });
69
-
70
- const filename = `${snapshot.timestamp.replace(/[:.]/g, "-")}.json`;
71
- const path = join(snapshotsDir, filename);
72
- writeFileSync(path, JSON.stringify(snapshot, null, 2));
73
- return path;
74
- }
75
-
76
- /**
77
- * Restore a snapshot to the generated directory.
78
- */
79
- export function restoreSnapshot(snapshotPath: string, generatedDir: string): void {
80
- const raw = readFileSync(snapshotPath, "utf-8");
81
- const snapshot: ArtifactSnapshot = JSON.parse(raw);
82
-
83
- mkdirSync(generatedDir, { recursive: true });
84
- for (const [filename, content] of Object.entries(snapshot.files)) {
85
- writeFileSync(join(generatedDir, filename), content);
86
- }
87
- }
88
-
89
- /**
90
- * List available snapshots.
91
- */
92
- export function listSnapshots(snapshotsDir: string): SnapshotInfo[] {
93
- if (!existsSync(snapshotsDir)) return [];
94
-
95
- const entries = readdirSync(snapshotsDir)
96
- .filter((f) => f.endsWith(".json"))
97
- .sort()
98
- .reverse();
99
-
100
- const snapshots: SnapshotInfo[] = [];
101
- for (const entry of entries) {
102
- try {
103
- const path = join(snapshotsDir, entry);
104
- const raw = readFileSync(path, "utf-8");
105
- const data = JSON.parse(raw);
106
- snapshots.push({
107
- path,
108
- timestamp: data.timestamp,
109
- resourceCount: data.resourceCount ?? 0,
110
- });
111
- } catch {}
112
- }
113
-
114
- return snapshots;
115
- }