@mimir-labs/core 0.3.0 → 0.5.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 (74) hide show
  1. package/README.md +16 -4
  2. package/dist/implementation/authoring/mimir-descriptor-loader.d.ts +2 -0
  3. package/dist/implementation/authoring/mimir-descriptor-loader.js +7 -0
  4. package/dist/implementation/authoring/mimir-descriptor-loader.js.map +1 -0
  5. package/dist/implementation/contracts/descriptor.d.ts +33 -0
  6. package/dist/implementation/contracts/descriptor.js +3 -0
  7. package/dist/implementation/contracts/descriptor.js.map +1 -0
  8. package/dist/implementation/contracts/resource.d.ts +109 -0
  9. package/dist/implementation/contracts/resource.js +3 -0
  10. package/dist/implementation/contracts/resource.js.map +1 -0
  11. package/dist/implementation/descriptors/descriptor-discovery.d.ts +2 -0
  12. package/dist/implementation/descriptors/descriptor-discovery.js +47 -0
  13. package/dist/implementation/descriptors/descriptor-discovery.js.map +1 -0
  14. package/dist/implementation/descriptors/descriptor-repository.d.ts +2 -0
  15. package/dist/implementation/descriptors/descriptor-repository.js +175 -0
  16. package/dist/implementation/descriptors/descriptor-repository.js.map +1 -0
  17. package/dist/implementation/generation/generate-service.d.ts +5 -0
  18. package/dist/implementation/generation/generate-service.js +77 -57
  19. package/dist/implementation/generation/generate-service.js.map +1 -1
  20. package/dist/implementation/generation/provenance/provenance-builder.d.ts +0 -1
  21. package/dist/implementation/generation/provenance/provenance-builder.js +0 -8
  22. package/dist/implementation/generation/provenance/provenance-builder.js.map +1 -1
  23. package/dist/implementation/generation/types.d.ts +2 -19
  24. package/dist/implementation/generators/aps-generator.js +1 -1
  25. package/dist/implementation/generators/aps-generator.js.map +1 -1
  26. package/dist/implementation/io/fs.d.ts +1 -0
  27. package/dist/implementation/io/fs.js +13 -0
  28. package/dist/implementation/io/fs.js.map +1 -1
  29. package/dist/implementation/knowledge/knowledge-engine.d.ts +8 -0
  30. package/dist/implementation/knowledge/knowledge-engine.js +40 -0
  31. package/dist/implementation/knowledge/knowledge-engine.js.map +1 -0
  32. package/dist/implementation/knowledge/knowledge-graph.d.ts +12 -0
  33. package/dist/implementation/knowledge/knowledge-graph.js +34 -0
  34. package/dist/implementation/knowledge/knowledge-graph.js.map +1 -0
  35. package/dist/implementation/knowledge/model.d.ts +44 -0
  36. package/dist/implementation/knowledge/model.js +3 -0
  37. package/dist/implementation/knowledge/model.js.map +1 -0
  38. package/dist/implementation/knowledge/persistence-policy.d.ts +21 -0
  39. package/dist/implementation/knowledge/persistence-policy.js +51 -0
  40. package/dist/implementation/knowledge/persistence-policy.js.map +1 -0
  41. package/dist/implementation/knowledge/providers.d.ts +36 -0
  42. package/dist/implementation/knowledge/providers.js +150 -0
  43. package/dist/implementation/knowledge/providers.js.map +1 -0
  44. package/dist/implementation/resource-discovery/design-token-extractor.d.ts +3 -0
  45. package/dist/implementation/resource-discovery/design-token-extractor.js +78 -0
  46. package/dist/implementation/resource-discovery/design-token-extractor.js.map +1 -0
  47. package/dist/implementation/resource-discovery/react-pattern-extractor.d.ts +3 -0
  48. package/dist/implementation/resource-discovery/react-pattern-extractor.js +49 -0
  49. package/dist/implementation/resource-discovery/react-pattern-extractor.js.map +1 -0
  50. package/dist/implementation/resource-discovery/relationship-extractor.d.ts +3 -0
  51. package/dist/implementation/resource-discovery/relationship-extractor.js +80 -0
  52. package/dist/implementation/resource-discovery/relationship-extractor.js.map +1 -0
  53. package/dist/implementation/resource-discovery/semantic-resource-classifier.d.ts +23 -0
  54. package/dist/implementation/resource-discovery/semantic-resource-classifier.js +267 -0
  55. package/dist/implementation/resource-discovery/semantic-resource-classifier.js.map +1 -0
  56. package/dist/implementation/resource-discovery/storybook-extractor.d.ts +3 -0
  57. package/dist/implementation/resource-discovery/storybook-extractor.js +102 -0
  58. package/dist/implementation/resource-discovery/storybook-extractor.js.map +1 -0
  59. package/dist/implementation/resource-discovery/typescript-analysis.d.ts +7 -0
  60. package/dist/implementation/resource-discovery/typescript-analysis.js +42 -0
  61. package/dist/implementation/resource-discovery/typescript-analysis.js.map +1 -0
  62. package/dist/implementation/resource-discovery/typescript-extractor.d.ts +8 -0
  63. package/dist/implementation/resource-discovery/typescript-extractor.js +195 -0
  64. package/dist/implementation/resource-discovery/typescript-extractor.js.map +1 -0
  65. package/dist/implementation/resource-discovery/typescript-public-api-extractor.d.ts +11 -0
  66. package/dist/implementation/resource-discovery/typescript-public-api-extractor.js +439 -0
  67. package/dist/implementation/resource-discovery/typescript-public-api-extractor.js.map +1 -0
  68. package/dist/implementation/resource-identity.d.ts +1 -0
  69. package/dist/implementation/resource-identity.js +7 -0
  70. package/dist/implementation/resource-identity.js.map +1 -1
  71. package/dist/implementation/services/authoring-service.d.ts +9 -0
  72. package/dist/implementation/services/authoring-service.js +335 -32
  73. package/dist/implementation/services/authoring-service.js.map +1 -1
  74. package/package.json +1 -1
package/README.md CHANGED
@@ -1,10 +1,22 @@
1
1
  # @mimir-labs/core
2
2
 
3
- Core business logic and reusable services for the Mimir CLI.
3
+ Software Knowledge Engine and reusable services for the Mimir CLI.
4
+
5
+ Mimir discovers software facts through Knowledge Providers, organizes them in
6
+ an in-memory Knowledge Graph, and applies an explicit Persistence Policy before
7
+ `author` writes versioned descriptors. `generate` remains independent: it
8
+ compiles persistent descriptor knowledge into APS without consulting authoring
9
+ providers.
4
10
 
5
11
  Public workflows include discovery, authoring, generation, validation,
6
12
  governance, context generation, synchronization, initialization, and doctor
7
- assessment. Author Knowledge sources live under `aps/knowledge`; generated APS
8
- artifacts remain under `dist/aps`.
13
+ assessment. Author Knowledge sources live in versioned `*.mimir.yaml`
14
+ descriptors maintained by `mimir author`; generated APS artifacts remain under
15
+ `dist/aps`.
16
+
17
+ The knowledge model is intentionally separate from APS. Knowledge extraction
18
+ can evolve without expanding the descriptor or protocol contract with every
19
+ derived fact.
9
20
 
10
- See extension guidance in [EXTENSIONS.md](./EXTENSIONS.md).
21
+ See [ARCHITECTURE.md](./ARCHITECTURE.md) for the knowledge pipeline and
22
+ [EXTENSIONS.md](./EXTENSIONS.md) for public extension guidance.
@@ -0,0 +1,2 @@
1
+ export { loadMimirDescriptors } from "../descriptors/descriptor-repository";
2
+ export type { MimirDescriptorLoadResult, MimirResourceDescriptor } from "../contracts/descriptor";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadMimirDescriptors = void 0;
4
+ // Backward-compatible re-export. Descriptor loading now lives in descriptors/descriptor-repository.
5
+ var descriptor_repository_1 = require("../descriptors/descriptor-repository");
6
+ Object.defineProperty(exports, "loadMimirDescriptors", { enumerable: true, get: function () { return descriptor_repository_1.loadMimirDescriptors; } });
7
+ //# sourceMappingURL=mimir-descriptor-loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mimir-descriptor-loader.js","sourceRoot":"","sources":["../../../src/implementation/authoring/mimir-descriptor-loader.ts"],"names":[],"mappings":";;;AAAA,oGAAoG;AACpG,8EAA4E;AAAnE,6HAAA,oBAAoB,OAAA"}
@@ -0,0 +1,33 @@
1
+ import type { ExtractedExample, ExtractedProp, ExtractedReactPatterns, ExtractedRelationship, ExtractionMetadata, PublicComponentApi, ResourceClassification } from "./resource";
2
+ export type MimirResourceDescriptor = {
3
+ kind: string;
4
+ name: string;
5
+ id?: string;
6
+ auto: {
7
+ source: {
8
+ file?: string;
9
+ symbol?: string;
10
+ public?: boolean;
11
+ };
12
+ props: Record<string, ExtractedProp>;
13
+ api?: PublicComponentApi;
14
+ classification?: ResourceClassification;
15
+ variants: string[];
16
+ storyFiles: string[];
17
+ relationships?: ExtractedRelationship[];
18
+ examples?: ExtractedExample[];
19
+ react?: ExtractedReactPatterns;
20
+ ai?: ExtractionMetadata;
21
+ };
22
+ human: {
23
+ description: string;
24
+ whenToUse: string[];
25
+ whenNotToUse: string[];
26
+ };
27
+ sourceRef: string;
28
+ };
29
+ export type MimirDescriptorLoadResult = {
30
+ descriptorFiles: string[];
31
+ resources: MimirResourceDescriptor[];
32
+ warnings: string[];
33
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=descriptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"descriptor.js","sourceRoot":"","sources":["../../../src/implementation/contracts/descriptor.ts"],"names":[],"mappings":""}
@@ -0,0 +1,109 @@
1
+ export type ExtractedProp = {
2
+ name: string;
3
+ type?: string;
4
+ required?: boolean;
5
+ };
6
+ export type SemanticResourceKind = "component" | "hook" | "context" | "provider" | "template" | "icon" | "page" | "utility" | "theme" | "token" | "configuration" | "story" | "internal" | "unknown";
7
+ export type ResourceClassification = {
8
+ kind: SemanticResourceKind;
9
+ confidence: number;
10
+ reasons: string[];
11
+ generateDescriptor: boolean;
12
+ };
13
+ export type PublicApiTypeDescriptor = {
14
+ kind: "primitive";
15
+ name: string;
16
+ } | {
17
+ kind: "literal";
18
+ value: string | number | boolean | null;
19
+ } | {
20
+ kind: "union";
21
+ values: Array<string | number | boolean | null>;
22
+ display: string;
23
+ } | {
24
+ kind: "enum";
25
+ name: string;
26
+ members: Array<string | number>;
27
+ display: string;
28
+ } | {
29
+ kind: "reference";
30
+ name: string;
31
+ display: string;
32
+ } | {
33
+ kind: "unknown";
34
+ display: string;
35
+ };
36
+ export type PublicApiProp = {
37
+ name: string;
38
+ type: PublicApiTypeDescriptor;
39
+ required: boolean;
40
+ inherited: boolean;
41
+ inheritedFrom?: string;
42
+ description?: string;
43
+ deprecated?: string | boolean;
44
+ default?: string | number | boolean | null;
45
+ remarks?: string;
46
+ };
47
+ export type PublicComponentApi = {
48
+ props: PublicApiProp[];
49
+ events: unknown[];
50
+ slots: unknown[];
51
+ methods: unknown[];
52
+ refs: unknown[];
53
+ };
54
+ export type ExtractedComponentFact = {
55
+ name: string;
56
+ filePath: string;
57
+ importName: string;
58
+ packageName: string;
59
+ props: Record<string, ExtractedProp>;
60
+ };
61
+ export type DiscoveredResourceFact = {
62
+ name: string;
63
+ filePath: string;
64
+ importName: string;
65
+ packageName: string;
66
+ classification: ResourceClassification;
67
+ };
68
+ export type StorybookFacts = {
69
+ variantsByComponent: Record<string, string[]>;
70
+ storyFilesByComponent: Record<string, string[]>;
71
+ examplesByComponent: Record<string, ExtractedExample[]>;
72
+ };
73
+ export type RelationshipType = "imports" | "exports" | "uses" | "composes" | "dependsOn" | "provides" | "consumes" | "references";
74
+ export type ExtractedRelationship = {
75
+ type: RelationshipType;
76
+ target: string;
77
+ confidence: number;
78
+ };
79
+ export type StaticValue = string | number | boolean | null | StaticValue[] | {
80
+ [key: string]: StaticValue;
81
+ };
82
+ export type ExtractedExample = {
83
+ name: string;
84
+ source: {
85
+ file: string;
86
+ };
87
+ story: string;
88
+ args?: Record<string, StaticValue>;
89
+ decorators?: string[];
90
+ play?: boolean;
91
+ };
92
+ export type DesignTokenCategory = "colors" | "spacing" | "typography" | "radius" | "shadows" | "zIndex" | "breakpoints";
93
+ export type ExtractedDesignTokens = Partial<Record<DesignTokenCategory, Record<string, StaticValue>>>;
94
+ export type ExtractedReactPatterns = {
95
+ forwardRef: boolean;
96
+ memo: boolean;
97
+ lazy: boolean;
98
+ suspense: boolean;
99
+ portal: boolean;
100
+ errorBoundary: boolean;
101
+ context: boolean;
102
+ provider: boolean;
103
+ customHook: boolean;
104
+ };
105
+ export type ExtractionMetadata = {
106
+ confidence?: number;
107
+ extractedAt?: string;
108
+ extractorVersion?: string;
109
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=resource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.js","sourceRoot":"","sources":["../../../src/implementation/contracts/resource.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export declare const DESCRIPTOR_SUFFIXES: string[];
2
+ export declare function discoverDescriptorFiles(cwd: string): Promise<string[]>;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DESCRIPTOR_SUFFIXES = void 0;
7
+ exports.discoverDescriptorFiles = discoverDescriptorFiles;
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const promises_1 = require("node:fs/promises");
10
+ exports.DESCRIPTOR_SUFFIXES = [".mimir.yaml", ".mimir.yml"];
11
+ function normalizeSlashes(value) {
12
+ return value.split(node_path_1.default.sep).join("/");
13
+ }
14
+ function shouldSkipDirectory(name) {
15
+ if (name === "node_modules" || name === "dist" || name === ".git") {
16
+ return true;
17
+ }
18
+ if (name.startsWith(".") && name !== ".aps") {
19
+ return true;
20
+ }
21
+ return false;
22
+ }
23
+ async function collectDescriptorFiles(dir) {
24
+ const entries = await (0, promises_1.readdir)(dir, { withFileTypes: true });
25
+ const files = [];
26
+ for (const entry of entries) {
27
+ const absolutePath = node_path_1.default.join(dir, entry.name);
28
+ if (entry.isDirectory()) {
29
+ if (shouldSkipDirectory(entry.name)) {
30
+ continue;
31
+ }
32
+ files.push(...(await collectDescriptorFiles(absolutePath)));
33
+ continue;
34
+ }
35
+ if (entry.isFile() && exports.DESCRIPTOR_SUFFIXES.some((suffix) => entry.name.endsWith(suffix))) {
36
+ files.push(absolutePath);
37
+ }
38
+ }
39
+ return files;
40
+ }
41
+ async function discoverDescriptorFiles(cwd) {
42
+ const descriptorPaths = await collectDescriptorFiles(cwd);
43
+ return descriptorPaths
44
+ .map((filePath) => normalizeSlashes(node_path_1.default.relative(cwd, filePath)))
45
+ .sort((a, b) => a.localeCompare(b));
46
+ }
47
+ //# sourceMappingURL=descriptor-discovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"descriptor-discovery.js","sourceRoot":"","sources":["../../../src/implementation/descriptors/descriptor-discovery.ts"],"names":[],"mappings":";;;;;;AA4CA,0DAKC;AAjDD,0DAA6B;AAC7B,+CAA2C;AAE9B,QAAA,mBAA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AC;YACxF,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAEM,KAAK,UAAU,uBAAuB,CAAC,GAAW;IACvD,MAAM,eAAe,GAAG,MAAM,sBAAsB,CAAC,GAAG,CAAC,CAAC;IAC1D,OAAO,eAAe;SACnB,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,gBAAgB,CAAC,mBAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;SACjE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { MimirDescriptorLoadResult } from "../contracts/descriptor";
2
+ export declare function loadMimirDescriptors(cwd: string): Promise<MimirDescriptorLoadResult>;
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.loadMimirDescriptors = loadMimirDescriptors;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const yaml_1 = require("yaml");
9
+ const fs_1 = require("../io/fs");
10
+ const json_1 = require("../io/json");
11
+ const descriptor_discovery_1 = require("./descriptor-discovery");
12
+ const SUPPORTED_KINDS = new Set([
13
+ "component",
14
+ "function",
15
+ "api",
16
+ "service",
17
+ "model",
18
+ "event",
19
+ "rule",
20
+ "example",
21
+ "pattern",
22
+ "migration"
23
+ ]);
24
+ function readStringArray(value, field, sourceRef) {
25
+ if (value === undefined) {
26
+ return [];
27
+ }
28
+ if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
29
+ throw new Error(`${sourceRef}: '${field}' must be an array of strings`);
30
+ }
31
+ return value;
32
+ }
33
+ function readPropsMap(value, field, sourceRef) {
34
+ if (value === undefined) {
35
+ return {};
36
+ }
37
+ if (!Array.isArray(value)) {
38
+ throw new Error(`${sourceRef}: '${field}' must be an array of prop objects`);
39
+ }
40
+ const props = {};
41
+ for (let index = 0; index < value.length; index += 1) {
42
+ const item = value[index];
43
+ if (!(0, json_1.isObject)(item) || typeof item.name !== "string" || item.name.trim() === "") {
44
+ throw new Error(`${sourceRef}: '${field}[${index}]' must include a non-empty 'name'`);
45
+ }
46
+ const name = item.name.trim();
47
+ props[name] = {
48
+ name,
49
+ type: typeof item.type === "string" ? item.type : undefined,
50
+ required: typeof item.required === "boolean" ? item.required : undefined
51
+ };
52
+ }
53
+ return props;
54
+ }
55
+ function readResource(value, sourceRef, resourcePath) {
56
+ if (!(0, json_1.isObject)(value)) {
57
+ throw new Error(`${sourceRef}: ${resourcePath} must be an object`);
58
+ }
59
+ const resource = value;
60
+ if (typeof resource.kind !== "string" || resource.kind.trim() === "") {
61
+ throw new Error(`${sourceRef}: ${resourcePath}.kind must be a non-empty string`);
62
+ }
63
+ if (typeof resource.name !== "string" || resource.name.trim() === "") {
64
+ throw new Error(`${sourceRef}: ${resourcePath}.name must be a non-empty string`);
65
+ }
66
+ const kind = resource.kind.trim().toLowerCase();
67
+ if (!SUPPORTED_KINDS.has(kind)) {
68
+ throw new Error(`${sourceRef}: ${resourcePath}.kind '${resource.kind}' is not supported by the descriptor contract`);
69
+ }
70
+ const autoNode = (0, json_1.isObject)(resource.auto) ? resource.auto : {};
71
+ const humanNode = (0, json_1.isObject)(resource.human) ? resource.human : {};
72
+ const sourceCandidate = (0, json_1.isObject)(autoNode.source)
73
+ ? autoNode.source
74
+ : (0, json_1.isObject)(resource.source)
75
+ ? resource.source
76
+ : {};
77
+ const source = (0, json_1.isObject)(sourceCandidate)
78
+ ? {
79
+ file: typeof sourceCandidate.file === "string" ? sourceCandidate.file : undefined,
80
+ symbol: typeof sourceCandidate.symbol === "string" ? sourceCandidate.symbol : undefined,
81
+ public: typeof sourceCandidate.public === "boolean" ? sourceCandidate.public : undefined
82
+ }
83
+ : {};
84
+ const props = readPropsMap(autoNode.props ?? resource.props, "auto.props", sourceRef);
85
+ const variants = readStringArray(autoNode.variants ?? resource.variants, "auto.variants", sourceRef);
86
+ const storyFiles = readStringArray(autoNode.storyFiles ?? resource.storyFiles, "auto.storyFiles", sourceRef);
87
+ return {
88
+ kind,
89
+ name: resource.name,
90
+ id: typeof resource.id === "string" ? resource.id : undefined,
91
+ auto: {
92
+ source,
93
+ props,
94
+ api: (0, json_1.isObject)(autoNode.api) ? autoNode.api : undefined,
95
+ classification: (0, json_1.isObject)(autoNode.classification) ? autoNode.classification : undefined,
96
+ variants,
97
+ storyFiles,
98
+ relationships: Array.isArray(autoNode.relationships) ? autoNode.relationships : undefined,
99
+ examples: Array.isArray(autoNode.examples) ? autoNode.examples : undefined,
100
+ react: (0, json_1.isObject)(autoNode.react) ? autoNode.react : undefined,
101
+ ai: (0, json_1.isObject)(autoNode.ai) ? autoNode.ai : undefined
102
+ },
103
+ human: {
104
+ description: typeof humanNode.description === "string"
105
+ ? humanNode.description
106
+ : typeof resource.description === "string"
107
+ ? resource.description
108
+ : "",
109
+ whenToUse: readStringArray(humanNode.whenToUse ?? resource.whenToUse, "human.whenToUse", sourceRef),
110
+ whenNotToUse: readStringArray(humanNode.whenNotToUse ?? resource.whenNotToUse, "human.whenNotToUse", sourceRef)
111
+ },
112
+ sourceRef
113
+ };
114
+ }
115
+ async function loadMimirDescriptors(cwd) {
116
+ const descriptorFiles = await (0, descriptor_discovery_1.discoverDescriptorFiles)(cwd);
117
+ const resources = [];
118
+ const warnings = [];
119
+ for (const sourceRef of descriptorFiles) {
120
+ const descriptorPath = node_path_1.default.join(cwd, sourceRef);
121
+ let raw;
122
+ try {
123
+ raw = (0, yaml_1.parse)(await (0, fs_1.readText)(descriptorPath));
124
+ }
125
+ catch (error) {
126
+ const message = error instanceof Error ? error.message : String(error);
127
+ warnings.push(`Invalid descriptor YAML at ${sourceRef}: ${message}`);
128
+ continue;
129
+ }
130
+ if (!(0, json_1.isObject)(raw)) {
131
+ warnings.push(`${sourceRef}: descriptor must be a YAML object`);
132
+ continue;
133
+ }
134
+ const schemaVersion = raw.schemaVersion;
135
+ if (schemaVersion === 1) {
136
+ if (!Array.isArray(raw.resources)) {
137
+ warnings.push(`${sourceRef}: resources must be an array for schemaVersion 1`);
138
+ continue;
139
+ }
140
+ for (let index = 0; index < raw.resources.length; index += 1) {
141
+ try {
142
+ const resource = readResource(raw.resources[index], sourceRef, `resources[${index}]`);
143
+ if (resource) {
144
+ resources.push(resource);
145
+ }
146
+ }
147
+ catch (error) {
148
+ const message = error instanceof Error ? error.message : String(error);
149
+ warnings.push(message);
150
+ }
151
+ }
152
+ continue;
153
+ }
154
+ if (schemaVersion === 2) {
155
+ try {
156
+ const resource = readResource(raw, sourceRef, "resource");
157
+ if (resource) {
158
+ resources.push(resource);
159
+ }
160
+ }
161
+ catch (error) {
162
+ const message = error instanceof Error ? error.message : String(error);
163
+ warnings.push(message);
164
+ }
165
+ continue;
166
+ }
167
+ warnings.push(`${sourceRef}: schemaVersion must be 1 or 2`);
168
+ }
169
+ return {
170
+ descriptorFiles,
171
+ resources,
172
+ warnings
173
+ };
174
+ }
175
+ //# sourceMappingURL=descriptor-repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"descriptor-repository.js","sourceRoot":"","sources":["../../../src/implementation/descriptors/descriptor-repository.ts"],"names":[],"mappings":";;;;;AAoLA,oDAgEC;AApPD,0DAA6B;AAC7B,+BAA6B;AAC7B,iCAAoC;AACpC,qCAAsC;AAWtC,iEAAiE;AAEjE,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC9B,WAAW;IACX,UAAU;IACV,KAAK;IACL,SAAS;IACT,OAAO;IACP,OAAO;IACP,MAAM;IACN,SAAS;IACT,SAAS;IACT,WAAW;CACZ,CAAC,CAAC;AAmBH,SAAS,eAAe,CAAC,KAAc,EAAE,KAAa,EAAE,SAAi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AI,CAAC,OAAO,CAAC,CAAC;YACzB,CAAC;YACD,SAAS;QACX,CAAC;QAED,QAAQ,CAAC,IAAI,CAAC,GAAG,SAAS,gCAAgC,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO;QACL,eAAe;QACf,SAAS;QACT,QAAQ;KACT,CAAC;AACJ,CAAC"}
@@ -2,5 +2,10 @@ import type { GenerateReport } from "./types";
2
2
  type GenerateOptions = {
3
3
  force?: boolean;
4
4
  };
5
+ export declare class NoDescriptorsFoundError extends Error {
6
+ readonly code = "NO_DESCRIPTORS_FOUND";
7
+ constructor();
8
+ }
9
+ export declare function compileApsFromDescriptors(cwd: string, options?: GenerateOptions): Promise<GenerateReport>;
5
10
  export declare function generateApsFromEvidence(cwd: string, options?: GenerateOptions): Promise<GenerateReport>;
6
11
  export {};
@@ -3,26 +3,79 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.NoDescriptorsFoundError = void 0;
7
+ exports.compileApsFromDescriptors = compileApsFromDescriptors;
6
8
  exports.generateApsFromEvidence = generateApsFromEvidence;
7
9
  const node_path_1 = __importDefault(require("node:path"));
8
10
  const fs_1 = require("../io/fs");
9
- const json_1 = require("../io/json");
10
11
  const compatibility_1 = require("../../protocol/compatibility");
11
12
  const governance_1 = require("../../protocol/governance");
12
- const readme_extractor_1 = require("./extractors/readme-extractor");
13
- const storybook_extractor_1 = require("./extractors/storybook-extractor");
14
- const typescript_extractor_1 = require("./extractors/typescript-extractor");
15
- const component_builder_1 = require("./resource-builders/component-builder");
16
13
  const example_builder_1 = require("./resource-builders/example-builder");
17
- const knowledge_loader_1 = require("../authoring/knowledge-loader");
14
+ const descriptor_repository_1 = require("../descriptors/descriptor-repository");
18
15
  const resource_identity_1 = require("../resource-identity");
19
- const APS_MANIFEST_RELATIVE_PATH = "./dist/aps/manifest.json";
16
+ const provenance_builder_1 = require("./provenance/provenance-builder");
17
+ class NoDescriptorsFoundError extends Error {
18
+ code = "NO_DESCRIPTORS_FOUND";
19
+ constructor() {
20
+ super("No descriptors found");
21
+ this.name = "NoDescriptorsFoundError";
22
+ }
23
+ }
24
+ exports.NoDescriptorsFoundError = NoDescriptorsFoundError;
20
25
  function hasHumanMetadata(component) {
21
26
  return component.description.trim() !== "" && component.whenToUse.length > 0 && component.whenNotToUse.length > 0;
22
27
  }
23
28
  function toUniqueSorted(values) {
24
29
  return [...new Set(values)].sort((a, b) => a.localeCompare(b));
25
30
  }
31
+ function buildComponentFromDescriptor(packageName, descriptor) {
32
+ const sourceFile = descriptor.auto.source.file ?? descriptor.sourceRef;
33
+ const storyFiles = descriptor.auto.storyFiles;
34
+ const variants = descriptor.auto.variants;
35
+ const authoredDescription = descriptor.human.description.trim();
36
+ const evidenceByField = {
37
+ id: { evidence: [(0, provenance_builder_1.fromPackageJson)()] },
38
+ name: { evidence: [(0, provenance_builder_1.fromTypeScript)(sourceFile)] },
39
+ package: { evidence: [(0, provenance_builder_1.fromPackageJson)()] },
40
+ import: { evidence: [(0, provenance_builder_1.fromTypeScript)(sourceFile)] },
41
+ description: {
42
+ evidence: authoredDescription !== "" ? [(0, provenance_builder_1.fromHumanKnowledge)(descriptor.sourceRef)] : [(0, provenance_builder_1.missingHumanSource)("description")]
43
+ },
44
+ props: { evidence: [(0, provenance_builder_1.fromTypeScript)(sourceFile)] },
45
+ variants: {
46
+ evidence: variants.length > 0
47
+ ? storyFiles.length > 0
48
+ ? storyFiles.map((file) => (0, provenance_builder_1.fromStorybook)(file))
49
+ : [(0, provenance_builder_1.fromTypeScript)(sourceFile)]
50
+ : [(0, provenance_builder_1.fromTypeScript)(sourceFile)]
51
+ },
52
+ whenToUse: {
53
+ evidence: descriptor.human.whenToUse.length > 0
54
+ ? [(0, provenance_builder_1.fromHumanKnowledge)(descriptor.sourceRef)]
55
+ : [(0, provenance_builder_1.missingHumanSource)("whenToUse")]
56
+ },
57
+ whenNotToUse: {
58
+ evidence: descriptor.human.whenNotToUse.length > 0
59
+ ? [(0, provenance_builder_1.fromHumanKnowledge)(descriptor.sourceRef)]
60
+ : [(0, provenance_builder_1.missingHumanSource)("whenNotToUse")]
61
+ }
62
+ };
63
+ return {
64
+ type: "component",
65
+ id: descriptor.id ?? (0, resource_identity_1.createComponentResourceId)(packageName, descriptor.name),
66
+ name: descriptor.name,
67
+ package: packageName,
68
+ import: descriptor.auto.source.symbol ?? descriptor.name,
69
+ description: authoredDescription,
70
+ props: descriptor.auto.props,
71
+ variants,
72
+ whenToUse: descriptor.human.whenToUse,
73
+ whenNotToUse: descriptor.human.whenNotToUse,
74
+ governance: {
75
+ fields: evidenceByField
76
+ }
77
+ };
78
+ }
26
79
  async function readPackageName(cwd) {
27
80
  const packageJsonPath = node_path_1.default.join(cwd, "package.json");
28
81
  const packageJson = await (0, fs_1.readJson)(packageJsonPath);
@@ -31,45 +84,12 @@ async function readPackageName(cwd) {
31
84
  }
32
85
  return packageJson.name;
33
86
  }
34
- async function ensureProviderDiscoverability(cwd) {
35
- const warnings = [];
36
- const packageJsonPath = node_path_1.default.join(cwd, "package.json");
37
- const packageJson = await (0, fs_1.readJson)(packageJsonPath);
38
- let changed = false;
39
- if (!(0, json_1.isObject)(packageJson.aps)) {
40
- packageJson.aps = {};
41
- changed = true;
42
- }
43
- const aps = packageJson.aps;
44
- if (aps.version === undefined) {
45
- aps.version = 1;
46
- changed = true;
47
- warnings.push("APS config version was missing and has been set to 1.");
48
- }
49
- if (aps.manifest !== APS_MANIFEST_RELATIVE_PATH) {
50
- const previous = typeof aps.manifest === "string" ? aps.manifest : "(not set)";
51
- aps.manifest = APS_MANIFEST_RELATIVE_PATH;
52
- changed = true;
53
- warnings.push(`APS manifest path updated from '${previous}' to '${APS_MANIFEST_RELATIVE_PATH}' for consistency with generated resources.`);
54
- }
55
- if ((0, json_1.isObject)(packageJson.exports)) {
56
- const exportsMap = packageJson.exports;
57
- if (exportsMap["./package.json"] !== "./package.json") {
58
- exportsMap["./package.json"] = "./package.json";
59
- changed = true;
60
- warnings.push("Added exports['./package.json'] for provider discovery compatibility.");
61
- }
62
- }
63
- else if (packageJson.exports !== undefined) {
64
- warnings.push("Package exports is not an object. Could not add exports['./package.json']; configure it manually for discovery compatibility.");
65
- }
66
- if (changed) {
67
- await (0, fs_1.writeJson)(packageJsonPath, packageJson);
68
- }
69
- return warnings;
70
- }
71
- async function generateApsFromEvidence(cwd, options = {}) {
87
+ async function compileApsFromDescriptors(cwd, options = {}) {
72
88
  const packageName = await readPackageName(cwd);
89
+ const descriptorResult = await (0, descriptor_repository_1.loadMimirDescriptors)(cwd);
90
+ if (descriptorResult.descriptorFiles.length === 0) {
91
+ throw new NoDescriptorsFoundError();
92
+ }
73
93
  const outputDir = node_path_1.default.join(cwd, "dist", "aps");
74
94
  const manifestPath = node_path_1.default.join(outputDir, "manifest.json");
75
95
  const componentsPath = node_path_1.default.join(outputDir, "components.json");
@@ -77,22 +97,18 @@ async function generateApsFromEvidence(cwd, options = {}) {
77
97
  if (alreadyExists && !options.force) {
78
98
  throw new Error("APS resources already exist in dist/aps. Re-run with --force to replace existing generated resources.");
79
99
  }
80
- const discoverabilityWarnings = await ensureProviderDiscoverability(cwd);
81
100
  await (0, fs_1.ensureDir)(outputDir);
82
- const [typescriptComponents, storybookFacts, readmeFacts] = await Promise.all([
83
- (0, typescript_extractor_1.extractTypeScriptComponents)(cwd, packageName),
84
- (0, storybook_extractor_1.extractStorybookFacts)(cwd),
85
- (0, readme_extractor_1.extractReadmeFacts)(cwd)
86
- ]);
87
- const components = await Promise.all(typescriptComponents.map(async (component) => {
88
- const resourceId = (0, resource_identity_1.createComponentResourceId)(component.packageName, component.name);
89
- const authored = await (0, knowledge_loader_1.loadComponentKnowledge)(cwd, resourceId);
90
- return (0, component_builder_1.buildComponentResource)(component, storybookFacts, readmeFacts, authored);
91
- }));
101
+ const unsupportedKinds = toUniqueSorted(descriptorResult.resources.filter((resource) => resource.kind !== "component").map((resource) => resource.kind));
102
+ const componentDescriptors = descriptorResult.resources.filter((resource) => resource.kind === "component");
103
+ const components = await Promise.all(componentDescriptors.map(async (descriptor) => buildComponentFromDescriptor(packageName, descriptor)));
92
104
  const exampleResult = (0, example_builder_1.buildExamplesNotImplemented)();
105
+ const descriptorWarnings = [...descriptorResult.warnings];
106
+ if (unsupportedKinds.length > 0) {
107
+ descriptorWarnings.push(`Descriptor resources ignored by generator v1 (unsupported kinds): ${unsupportedKinds.join(", ")}.`);
108
+ }
93
109
  const output = {
94
110
  components,
95
- warnings: [...exampleResult.warnings, ...discoverabilityWarnings],
111
+ warnings: [...exampleResult.warnings, ...descriptorWarnings],
96
112
  missingHumanMetadata: toUniqueSorted(components
97
113
  .filter((component) => !hasHumanMetadata(component))
98
114
  .map((component) => component.name))
@@ -109,6 +125,7 @@ async function generateApsFromEvidence(cwd, options = {}) {
109
125
  const governanceResult = (0, governance_1.validateGovernance)(manifest);
110
126
  return {
111
127
  outputDir,
128
+ descriptorsCompiled: descriptorResult.descriptorFiles.length,
112
129
  generatedResources: output.components.length,
113
130
  warnings: output.warnings,
114
131
  missingHumanMetadata: output.missingHumanMetadata,
@@ -124,4 +141,7 @@ async function generateApsFromEvidence(cwd, options = {}) {
124
141
  }
125
142
  };
126
143
  }
144
+ async function generateApsFromEvidence(cwd, options = {}) {
145
+ return compileApsFromDescriptors(cwd, options);
146
+ }
127
147
  //# sourceMappingURL=generate-service.js.map