@aaac/contracts 0.0.1 → 0.1.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.
package/dist/index.d.ts CHANGED
@@ -1,9 +1,344 @@
1
- /** Package version string. */
2
- declare const version = "0.0.1";
3
- /** Minimal contract definition placeholder. */
4
- interface ContractDefinition {
1
+ import { z } from 'zod';
2
+
3
+ /** Supported AaaC schema versions (compiler accepts only these). */
4
+ declare const SUPPORTED_SCHEMA_VERSIONS: readonly ["aaac/0.1"];
5
+ /** Pattern for schema version field: `aaac/x.y` */
6
+ declare const SCHEMA_VERSION_PATTERN: RegExp;
7
+ declare const JSONSchemaRefSchema: z.ZodUnion<readonly [z.ZodObject<{
8
+ schema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
9
+ }, z.core.$strip>, z.ZodObject<{
10
+ $ref: z.ZodString;
11
+ }, z.core.$strip>]>;
12
+ declare const OptionSchema: z.ZodObject<{
13
+ name: z.ZodString;
14
+ schema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
15
+ required: z.ZodOptional<z.ZodBoolean>;
16
+ description: z.ZodOptional<z.ZodString>;
17
+ }, z.core.$strip>;
18
+ declare const ArtifactSlotValueSchema: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
19
+ artifact: z.ZodString;
20
+ direction: z.ZodEnum<{
21
+ read: "read";
22
+ write: "write";
23
+ readwrite: "readwrite";
24
+ }>;
25
+ }, z.core.$strip>]>;
26
+ declare const OperationSchema: z.ZodObject<{
27
+ description: z.ZodString;
28
+ agentWorkflow: z.ZodOptional<z.ZodString>;
29
+ agentTask: z.ZodOptional<z.ZodString>;
30
+ handler: z.ZodOptional<z.ZodString>;
31
+ options: z.ZodOptional<z.ZodArray<z.ZodObject<{
32
+ name: z.ZodString;
33
+ schema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
34
+ required: z.ZodOptional<z.ZodBoolean>;
35
+ description: z.ZodOptional<z.ZodString>;
36
+ }, z.core.$strip>>>;
37
+ input: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
38
+ schema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
39
+ }, z.core.$strip>, z.ZodObject<{
40
+ $ref: z.ZodString;
41
+ }, z.core.$strip>]>>;
42
+ output: z.ZodObject<{
43
+ success: z.ZodUnion<readonly [z.ZodObject<{
44
+ schema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
45
+ }, z.core.$strip>, z.ZodObject<{
46
+ $ref: z.ZodString;
47
+ }, z.core.$strip>]>;
48
+ failed: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
49
+ schema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
50
+ }, z.core.$strip>, z.ZodObject<{
51
+ $ref: z.ZodString;
52
+ }, z.core.$strip>]>>;
53
+ }, z.core.$strip>;
54
+ artifactSlots: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
55
+ artifact: z.ZodString;
56
+ direction: z.ZodEnum<{
57
+ read: "read";
58
+ write: "write";
59
+ readwrite: "readwrite";
60
+ }>;
61
+ }, z.core.$strip>]>>>;
62
+ riskLevel: z.ZodOptional<z.ZodEnum<{
63
+ low: "low";
64
+ medium: "medium";
65
+ high: "high";
66
+ }>>;
67
+ idempotent: z.ZodOptional<z.ZodBoolean>;
68
+ requiresConfirmation: z.ZodOptional<z.ZodBoolean>;
69
+ execution: z.ZodOptional<z.ZodObject<{
70
+ timeoutMs: z.ZodOptional<z.ZodNumber>;
71
+ costCeilingUsd: z.ZodOptional<z.ZodNumber>;
72
+ }, z.core.$strip>>;
73
+ memoryRef: z.ZodOptional<z.ZodObject<{
74
+ input: z.ZodOptional<z.ZodBoolean>;
75
+ output: z.ZodOptional<z.ZodBoolean>;
76
+ }, z.core.$strip>>;
77
+ }, z.core.$strip>;
78
+ declare const ComponentSchema: z.ZodObject<{
79
+ schema: z.ZodString;
80
+ info: z.ZodObject<{
81
+ id: z.ZodString;
82
+ version: z.ZodString;
83
+ description: z.ZodOptional<z.ZodString>;
84
+ }, z.core.$strip>;
85
+ implementation: z.ZodOptional<z.ZodString>;
86
+ projections: z.ZodArray<z.ZodEnum<{
87
+ library: "library";
88
+ cli: "cli";
89
+ mcp: "mcp";
90
+ claude: "claude";
91
+ openai: "openai";
92
+ }>>;
93
+ operations: z.ZodRecord<z.ZodString, z.ZodObject<{
94
+ description: z.ZodString;
95
+ agentWorkflow: z.ZodOptional<z.ZodString>;
96
+ agentTask: z.ZodOptional<z.ZodString>;
97
+ handler: z.ZodOptional<z.ZodString>;
98
+ options: z.ZodOptional<z.ZodArray<z.ZodObject<{
99
+ name: z.ZodString;
100
+ schema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
101
+ required: z.ZodOptional<z.ZodBoolean>;
102
+ description: z.ZodOptional<z.ZodString>;
103
+ }, z.core.$strip>>>;
104
+ input: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
105
+ schema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
106
+ }, z.core.$strip>, z.ZodObject<{
107
+ $ref: z.ZodString;
108
+ }, z.core.$strip>]>>;
109
+ output: z.ZodObject<{
110
+ success: z.ZodUnion<readonly [z.ZodObject<{
111
+ schema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
112
+ }, z.core.$strip>, z.ZodObject<{
113
+ $ref: z.ZodString;
114
+ }, z.core.$strip>]>;
115
+ failed: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
116
+ schema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
117
+ }, z.core.$strip>, z.ZodObject<{
118
+ $ref: z.ZodString;
119
+ }, z.core.$strip>]>>;
120
+ }, z.core.$strip>;
121
+ artifactSlots: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
122
+ artifact: z.ZodString;
123
+ direction: z.ZodEnum<{
124
+ read: "read";
125
+ write: "write";
126
+ readwrite: "readwrite";
127
+ }>;
128
+ }, z.core.$strip>]>>>;
129
+ riskLevel: z.ZodOptional<z.ZodEnum<{
130
+ low: "low";
131
+ medium: "medium";
132
+ high: "high";
133
+ }>>;
134
+ idempotent: z.ZodOptional<z.ZodBoolean>;
135
+ requiresConfirmation: z.ZodOptional<z.ZodBoolean>;
136
+ execution: z.ZodOptional<z.ZodObject<{
137
+ timeoutMs: z.ZodOptional<z.ZodNumber>;
138
+ costCeilingUsd: z.ZodOptional<z.ZodNumber>;
139
+ }, z.core.$strip>>;
140
+ memoryRef: z.ZodOptional<z.ZodObject<{
141
+ input: z.ZodOptional<z.ZodBoolean>;
142
+ output: z.ZodOptional<z.ZodBoolean>;
143
+ }, z.core.$strip>>;
144
+ }, z.core.$strip>>;
145
+ }, z.core.$strip>;
146
+ type ComponentDSL = z.infer<typeof ComponentSchema>;
147
+ type OperationDSL = z.infer<typeof OperationSchema>;
148
+ type OptionDSL = z.infer<typeof OptionSchema>;
149
+ type JSONSchemaRefDSL = z.infer<typeof JSONSchemaRefSchema>;
150
+
151
+ declare class ComponentParseError extends Error {
152
+ readonly filePath?: string | undefined;
153
+ readonly cause?: unknown | undefined;
154
+ constructor(message: string, filePath?: string | undefined, cause?: unknown | undefined);
155
+ }
156
+ /**
157
+ * Parse and validate a component YAML string.
158
+ * When `filePath` is provided, `$ref` pointers resolve relative to its directory.
159
+ */
160
+ declare function parseComponentString(content: string, filePath?: string): ComponentDSL;
161
+ /**
162
+ * Read a component YAML file, resolve `$ref` pointers, and validate.
163
+ */
164
+ declare function parseComponentFile(filePath: string): Promise<ComponentDSL>;
165
+
166
+ /** JSON Schema object (resolved, JSON-serializable). */
167
+ type JSONSchema = Record<string, unknown>;
168
+ /** Resolved JSON Schema reference — inline schema or resolved $ref target. */
169
+ type JSONSchemaRef = {
170
+ schema: JSONSchema;
171
+ } | {
172
+ $ref: string;
173
+ } | JSONSchema;
174
+ type ProjectionTarget = "library" | "cli" | "mcp" | "claude" | "openai";
175
+ type ArtifactDirection = "read" | "write" | "readwrite";
176
+ type RiskLevel = "low" | "medium" | "high";
177
+ interface OptionIR {
5
178
  name: string;
6
- version: string;
179
+ schema: JSONSchema;
180
+ required: boolean;
181
+ description?: string;
182
+ }
183
+ interface OperationMemoryRefConfig {
184
+ input?: boolean;
185
+ output?: boolean;
186
+ }
187
+ interface OperationIR {
188
+ description: string;
189
+ agentWorkflow?: string;
190
+ agentTask?: string;
191
+ handler?: string;
192
+ memoryRef?: OperationMemoryRefConfig;
193
+ options: OptionIR[];
194
+ input?: JSONSchemaRef;
195
+ output: {
196
+ success: JSONSchemaRef;
197
+ failed?: JSONSchemaRef;
198
+ };
199
+ errorModel: {
200
+ failureClasses: string[];
201
+ };
202
+ artifactSlots: Record<string, {
203
+ artifact: string;
204
+ direction: ArtifactDirection;
205
+ }>;
206
+ riskLevel: RiskLevel;
207
+ idempotent: boolean;
208
+ requiresConfirmation: boolean;
209
+ execution: {
210
+ timeoutMs?: number;
211
+ costCeilingUsd?: number;
212
+ };
213
+ }
214
+ interface ComponentIR {
215
+ schema: string;
216
+ info: {
217
+ id: string;
218
+ version: string;
219
+ description?: string;
220
+ };
221
+ implementation?: string;
222
+ projections: ProjectionTarget[];
223
+ operations: Record<string, OperationIR>;
224
+ }
225
+
226
+ declare class ComponentCompileError extends Error {
227
+ constructor(message: string);
228
+ }
229
+ declare class ComponentValidationError extends ComponentCompileError {
230
+ constructor(message: string);
231
+ }
232
+
233
+ /**
234
+ * Extract failure class names from a resolved failed output schema.
235
+ *
236
+ * Checks, in order:
237
+ * 1. Top-level `failure_classes` array
238
+ * 2. `properties.failure_class.enum`
239
+ * 3. `oneOf` entries with `const` or `properties.failure_class.const`
240
+ */
241
+ declare function extractFailureClasses(failedRef: JSONSchemaRef | undefined): string[];
242
+ interface CompileComponentOptions {
243
+ basePath?: string;
244
+ /** When true (default), validate implementation file and agent workflow/task IDs. */
245
+ validate?: boolean;
246
+ }
247
+ /**
248
+ * Compile a validated Component DSL into Component IR.
249
+ */
250
+ declare function compileComponent(dsl: ComponentDSL, options?: CompileComponentOptions): ComponentIR;
251
+ /**
252
+ * Compile a validated Component DSL into Component IR, optionally validating
253
+ * implementation references.
254
+ */
255
+ declare function compileComponentAsync(dsl: ComponentDSL, options?: CompileComponentOptions): Promise<ComponentIR>;
256
+ /**
257
+ * Parse a component YAML file and compile it to IR.
258
+ */
259
+ declare function compileComponentFile(filePath: string, options?: Omit<CompileComponentOptions, "basePath">): Promise<ComponentIR>;
260
+
261
+ interface ValidationOptions {
262
+ /** Base directory for resolving relative implementation paths. */
263
+ basePath: string;
264
+ }
265
+ interface ImplementationIds {
266
+ workflowIds: string[];
267
+ taskIds: string[];
7
268
  }
269
+ /**
270
+ * Extract workflow and task IDs from a parsed agent-contracts DSL document.
271
+ *
272
+ * Looks for top-level `workflows` / `tasks` keys (map of ID → definition).
273
+ */
274
+ declare function extractImplementationIds(content: unknown): ImplementationIds;
275
+ /**
276
+ * Validate a compiled Component IR against its implementation DSL.
277
+ *
278
+ * Checks:
279
+ * - implementation file exists (when specified)
280
+ * - agentWorkflow IDs exist in implementation DSL
281
+ * - agentTask IDs exist in implementation DSL
282
+ */
283
+ declare function validateComponent(ir: ComponentIR, options: ValidationOptions): Promise<void>;
284
+
285
+ declare class RefResolutionError extends Error {
286
+ readonly ref: string;
287
+ constructor(ref: string, message: string);
288
+ }
289
+ interface ResolveRefsOptions {
290
+ basePath?: string;
291
+ }
292
+ /**
293
+ * Resolves `$ref` pointers within a value tree.
294
+ *
295
+ * - Internal refs (`#/path/to/key`) resolve against `root`.
296
+ * - External file refs (`./path/file.yaml` or `./file.yaml#/pointer`) resolve
297
+ * relative to `basePath`.
298
+ */
299
+ declare function resolveRefs<T>(value: T, options?: ResolveRefsOptions): T;
300
+
301
+ interface GeneratedFile {
302
+ path: string;
303
+ content: string;
304
+ overwrite: boolean;
305
+ /** Set when a file is skipped (e.g. existing handler). */
306
+ warning?: string;
307
+ }
308
+ interface GenerateOptions {
309
+ outputDir: string;
310
+ componentPath: string;
311
+ }
312
+ interface Generator {
313
+ generate(ir: ComponentIR, options: GenerateOptions): GeneratedFile[];
314
+ }
315
+
316
+ declare const typesGenerator: Generator;
317
+
318
+ declare const clientGenerator: Generator;
319
+
320
+ declare const runtimeGenerator: Generator;
321
+
322
+ declare const cliGenerator: Generator;
323
+
324
+ declare const handlerGenerator: Generator;
325
+
326
+ /**
327
+ * Run all code generators for a compiled Component IR.
328
+ */
329
+ declare function generateAll(ir: ComponentIR, options: GenerateOptions): GeneratedFile[];
330
+ /**
331
+ * Write generated files to disk, respecting overwrite policy.
332
+ * - `overwrite: true` — always write (generated/ artifacts)
333
+ * - `overwrite: false` — skip if target already exists (handlers, cli stub)
334
+ */
335
+ declare function writeGeneratedFiles(files: GeneratedFile[], outputDir: string): Promise<{
336
+ written: string[];
337
+ skipped: string[];
338
+ warnings: string[];
339
+ }>;
340
+
341
+ /** Package version string. */
342
+ declare const version: string;
8
343
 
9
- export { type ContractDefinition, version };
344
+ export { type ArtifactDirection, ArtifactSlotValueSchema, type CompileComponentOptions, ComponentCompileError, type ComponentDSL, type ComponentIR, ComponentParseError, ComponentSchema, ComponentValidationError, type GenerateOptions, type GeneratedFile, type Generator, type ImplementationIds, type JSONSchema, type JSONSchemaRef, type JSONSchemaRefDSL, JSONSchemaRefSchema, type OperationDSL, type OperationIR, OperationSchema, type OptionDSL, type OptionIR, OptionSchema, type ProjectionTarget, RefResolutionError, type RiskLevel, SCHEMA_VERSION_PATTERN, SUPPORTED_SCHEMA_VERSIONS, type ValidationOptions, cliGenerator, clientGenerator, compileComponent, compileComponentAsync, compileComponentFile, extractFailureClasses, extractImplementationIds, generateAll, handlerGenerator, parseComponentFile, parseComponentString, resolveRefs, runtimeGenerator, typesGenerator, validateComponent, version, writeGeneratedFiles };
package/dist/index.js CHANGED
@@ -1,6 +1,66 @@
1
+ import {
2
+ ArtifactSlotValueSchema,
3
+ ComponentCompileError,
4
+ ComponentParseError,
5
+ ComponentSchema,
6
+ ComponentValidationError,
7
+ JSONSchemaRefSchema,
8
+ OperationSchema,
9
+ OptionSchema,
10
+ RefResolutionError,
11
+ SCHEMA_VERSION_PATTERN,
12
+ SUPPORTED_SCHEMA_VERSIONS,
13
+ cliGenerator,
14
+ clientGenerator,
15
+ compileComponent,
16
+ compileComponentAsync,
17
+ compileComponentFile,
18
+ extractFailureClasses,
19
+ extractImplementationIds,
20
+ generateAll,
21
+ handlerGenerator,
22
+ parseComponentFile,
23
+ parseComponentString,
24
+ resolveRefs,
25
+ runtimeGenerator,
26
+ typesGenerator,
27
+ validateComponent,
28
+ writeGeneratedFiles
29
+ } from "./chunk-MMFA6S5O.js";
30
+
1
31
  // src/index.ts
2
- var version = "0.0.1";
32
+ import { createRequire } from "module";
33
+ var require2 = createRequire(import.meta.url);
34
+ var pkg = require2("../package.json");
35
+ var version = pkg.version;
3
36
  export {
4
- version
37
+ ArtifactSlotValueSchema,
38
+ ComponentCompileError,
39
+ ComponentParseError,
40
+ ComponentSchema,
41
+ ComponentValidationError,
42
+ JSONSchemaRefSchema,
43
+ OperationSchema,
44
+ OptionSchema,
45
+ RefResolutionError,
46
+ SCHEMA_VERSION_PATTERN,
47
+ SUPPORTED_SCHEMA_VERSIONS,
48
+ cliGenerator,
49
+ clientGenerator,
50
+ compileComponent,
51
+ compileComponentAsync,
52
+ compileComponentFile,
53
+ extractFailureClasses,
54
+ extractImplementationIds,
55
+ generateAll,
56
+ handlerGenerator,
57
+ parseComponentFile,
58
+ parseComponentString,
59
+ resolveRefs,
60
+ runtimeGenerator,
61
+ typesGenerator,
62
+ validateComponent,
63
+ version,
64
+ writeGeneratedFiles
5
65
  };
6
66
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/** Package version string. */\nexport const version = \"0.0.1\";\n\n/** Minimal contract definition placeholder. */\nexport interface ContractDefinition {\n name: string;\n version: string;\n}\n"],"mappings":";AACO,IAAM,UAAU;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\n\nconst require = createRequire(import.meta.url);\nconst pkg = require(\"../package.json\") as { version: string };\n\n/** Package version string. */\nexport const version = pkg.version;\n\nexport {\n ComponentSchema,\n OperationSchema,\n OptionSchema,\n JSONSchemaRefSchema,\n ArtifactSlotValueSchema,\n SUPPORTED_SCHEMA_VERSIONS,\n SCHEMA_VERSION_PATTERN,\n type ComponentDSL,\n type OperationDSL,\n type OptionDSL,\n type JSONSchemaRefDSL,\n} from \"./schema.js\";\n\nexport {\n parseComponentFile,\n parseComponentString,\n ComponentParseError,\n} from \"./parser.js\";\n\nexport type {\n ComponentIR,\n OperationIR,\n OptionIR,\n JSONSchema,\n JSONSchemaRef,\n ProjectionTarget,\n ArtifactDirection,\n RiskLevel,\n} from \"./ir.js\";\n\nexport {\n compileComponent,\n compileComponentAsync,\n compileComponentFile,\n extractFailureClasses,\n ComponentCompileError,\n type CompileComponentOptions,\n} from \"./compiler.js\";\n\nexport {\n validateComponent,\n extractImplementationIds,\n ComponentValidationError,\n type ValidationOptions,\n type ImplementationIds,\n} from \"./validation.js\";\n\nexport { resolveRefs, RefResolutionError } from \"./ref-resolver.js\";\n\nexport {\n generateAll,\n writeGeneratedFiles,\n typesGenerator,\n clientGenerator,\n runtimeGenerator,\n cliGenerator,\n handlerGenerator,\n type GeneratedFile,\n type GenerateOptions,\n type Generator,\n} from \"./generators/index.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,qBAAqB;AAE9B,IAAMA,WAAU,cAAc,YAAY,GAAG;AAC7C,IAAM,MAAMA,SAAQ,iBAAiB;AAG9B,IAAM,UAAU,IAAI;","names":["require"]}
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@aaac/contracts",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "Contract definitions for the AAAC (Agent-Assisted Architecture Contracts) toolchain",
5
5
  "type": "module",
6
+ "bin": {
7
+ "aaac": "./dist/cli/index.js"
8
+ },
6
9
  "main": "dist/index.js",
7
10
  "types": "dist/index.d.ts",
8
11
  "exports": {
@@ -20,6 +23,8 @@
20
23
  "build": "tsup",
21
24
  "clean": "rm -rf dist",
22
25
  "test": "vitest run",
26
+ "contract:validate": "cli-contracts validate",
27
+ "contract:generate": "cli-contracts generate",
23
28
  "prepublishOnly": "npm run clean && npm run build"
24
29
  },
25
30
  "publishConfig": {
@@ -33,5 +38,16 @@
33
38
  "license": "MIT",
34
39
  "engines": {
35
40
  "node": ">=20.0.0"
41
+ },
42
+ "dependencies": {
43
+ "yaml": "^2.8.3",
44
+ "zod": "^4.0.0"
45
+ },
46
+ "devDependencies": {
47
+ "cli-contracts": "^0.32.3",
48
+ "commander": "^15.0.0",
49
+ "tsup": "^8.5.0",
50
+ "typescript": "^5.9.0",
51
+ "vitest": "^4.0.0"
36
52
  }
37
53
  }