agent_patch
runs/2026-02-27__21-30-28__gpt-5-1-codex-mini/flux-commit-7af773c0/flux-commit-7af773c0.1-of-1.2026-02-27__21-30-28__gpt-5-1-codex-mini/agent-logs/agent.patch
11239 bytes
diff --git a/app/src/codegen.ts b/app/src/codegen.ts
new file mode 100644
index 0000000..ef18411
--- /dev/null
+++ b/app/src/codegen.ts
@@ -0,0 +1,183 @@
+import * as z from './types/base';
+
+const __INCOMPLETE__ = '__INCOMPLETE__';
+
+export type Identity<T> = T;
+
+export type TypeResult = Identity<{
+ id: string;
+ schema: z.ZodType<any, any>;
+ type: string;
+ dependencies: TypeResult[];
+}>;
+
+const isOptional = (schema: z.ZodType<any, any>): boolean => {
+ const def: any = (schema as any)._def;
+ if (def.t === z.ZodTypes.undefined) {
+ return true;
+ }
+ if (def.t === z.ZodTypes.intersection) {
+ return isOptional(def.left) || isOptional(def.right);
+ }
+ if (def.t === z.ZodTypes.union) {
+ return def.options.some((option: z.ZodType<any, any>) => isOptional(option));
+ }
+ return false;
+};
+
+export class ZodCodeGenerator {
+ private seen: TypeResult[] = [];
+ private serial: number = 0;
+
+ findBySchema = (schema: z.ZodType<any, any>) => this.seen.find(result => result.schema === schema);
+ findById = (id: string) => this.seen.find(result => result.id === id);
+ setType = (id: string, type: string) => {
+ const target = this.findById(id);
+ if (target) {
+ target.type = type;
+ }
+ };
+ dump = () => this.seen;
+
+ generate = (schema: z.ZodType<any, any>): TypeResult => {
+ const existing = this.findBySchema(schema);
+ if (existing) {
+ return existing;
+ }
+
+ const id = `Type${this.serial}`;
+ this.serial += 1;
+
+ const result: TypeResult = {
+ id,
+ schema,
+ type: __INCOMPLETE__,
+ dependencies: [],
+ };
+
+ this.seen.push(result);
+
+ const def: any = (schema as any)._def;
+ switch (def.t) {
+ case z.ZodTypes.string:
+ this.setType(id, 'string');
+ break;
+ case z.ZodTypes.number:
+ this.setType(id, 'number');
+ break;
+ case z.ZodTypes.boolean:
+ this.setType(id, 'boolean');
+ break;
+ case z.ZodTypes.date:
+ this.setType(id, 'Date');
+ break;
+ case z.ZodTypes.bigint:
+ this.setType(id, 'bigint');
+ break;
+ case z.ZodTypes.null:
+ this.setType(id, 'null');
+ break;
+ case z.ZodTypes.undefined:
+ this.setType(id, 'undefined');
+ break;
+ case z.ZodTypes.any:
+ this.setType(id, 'any');
+ break;
+ case z.ZodTypes.unknown:
+ this.setType(id, 'unknown');
+ break;
+ case z.ZodTypes.void:
+ this.setType(id, 'void');
+ break;
+ case z.ZodTypes.array: {
+ const childSchema: z.ZodType<any, any> = def.type;
+ const childType = this.generate(childSchema);
+ result.dependencies.push(childType);
+ this.setType(id, `${childType.id}[]`);
+ break;
+ }
+ case z.ZodTypes.record: {
+ const childSchema: z.ZodType<any, any> = def.valueType;
+ const childType = this.generate(childSchema);
+ result.dependencies.push(childType);
+ this.setType(id, `Record<string, ${childType.id}>`);
+ break;
+ }
+ case z.ZodTypes.tuple: {
+ const tupleItems: string[] = [];
+ for (const item of def.items) {
+ const childType = this.generate(item);
+ tupleItems.push(childType.id);
+ result.dependencies.push(childType);
+ }
+ this.setType(id, `[${tupleItems.join(', ')}]`);
+ break;
+ }
+ case z.ZodTypes.union: {
+ const optionIds: string[] = [];
+ for (const option of def.options) {
+ const childType = this.generate(option);
+ optionIds.push(childType.id);
+ result.dependencies.push(childType);
+ }
+ this.setType(id, optionIds.join(' | '));
+ break;
+ }
+ case z.ZodTypes.intersection: {
+ const left = this.generate(def.left);
+ const right = this.generate(def.right);
+ result.dependencies.push(left, right);
+ this.setType(id, `${left.id} & ${right.id}`);
+ break;
+ }
+ case z.ZodTypes.object: {
+ const shape: z.ZodRawShape = def.shape();
+ const objectLines: string[] = [];
+ for (const key of Object.keys(shape)) {
+ const childSchema: z.ZodType<any, any> = shape[key];
+ const childType = this.generate(childSchema);
+ const OPTKEY = isOptional(childSchema) ? '?' : '';
+ objectLines.push(`${key}${OPTKEY}: ${childType.id}`);
+ result.dependencies.push(childType);
+ }
+ const objectText = `{
+ ${objectLines.join(';\n ')}
+}`;
+ this.setType(id, objectText);
+ break;
+ }
+ case z.ZodTypes.function: {
+ const args = this.generate(def.args);
+ const returns = this.generate(def.returns);
+ result.dependencies.push(args, returns);
+ this.setType(id, `(...args: ${args.id}) => ${returns.id}`);
+ break;
+ }
+ case z.ZodTypes.promise: {
+ const inner = this.generate(def.type);
+ result.dependencies.push(inner);
+ this.setType(id, `Promise<${inner.id}>`);
+ break;
+ }
+ case z.ZodTypes.literal:
+ this.setType(id, JSON.stringify(def.value));
+ break;
+ case z.ZodTypes.enum:
+ this.setType(id, def.values.map((value: string) => JSON.stringify(value)).join(' | '));
+ break;
+ case z.ZodTypes.lazy: {
+ const innerSchema: z.ZodType<any, any> = def.getter();
+ const inner = this.generate(innerSchema);
+ result.dependencies.push(inner);
+ this.setType(id, inner.id);
+ break;
+ }
+ default:
+ this.setType(id, __INCOMPLETE__);
+ }
+
+ return result;
+ };
+
+ static create = () => new ZodCodeGenerator();
+}
diff --git a/tmp/agent-patch-flux-commit-7af773c0.1-of-1.2026-02-27__21-30-28__gpt-5-1-codex-mini/app/src/index.ts b/app/src/index.ts
index 480ceff..7f37746 100644
--- a/tmp/agent-patch-flux-commit-7af773c0.1-of-1.2026-02-27__21-30-28__gpt-5-1-codex-mini/app/src/index.ts
+++ b/app/src/index.ts
@@ -21,10 +21,12 @@ import { ZodLazy, ZodLazyDef } from './types/lazy';
import { ZodLiteral, ZodLiteralDef } from './types/literal';
import { ZodEnum, ZodEnumDef } from './types/enum';
import { ZodPromise, ZodPromiseDef } from './types/promise';
-import { TypeOf, ZodType, ZodTypeAny } from './types/base';
-import { ZodError } from './ZodError';
+import { TypeOf, ZodType, ZodTypeAny, ZodTypeDef, ZodTypes } from './types/base';
+import { ZodError, ZodErrorCode } from './ZodError';
import { toZod } from './toZod';
+import { ErrorMap } from './errorMap';
+import { ZodCodeGenerator } from './codegen';
// import { ZodLazyObject, ZodLazyObjectDef } from './types/lazyobject';
type ZodDef =
@@ -159,13 +161,18 @@ export {
ZodLiteral,
ZodEnum,
ZodPromise,
+ ZodCodeGenerator,
ZodType,
ZodType as Schema,
ZodTypeAny,
ZodDef,
ZodError,
+ ZodErrorCode,
+ ErrorMap,
};
+export { ZodTypeDef, ZodTypes };
+
export type lazyobject<T extends object> = ZodObject<{ [k in keyof T]: ZodType<T[k], any> }>;
// export namespace lazy {
// export type objectType<T extends object> = ZodObject<{ [k in keyof T]: ZodType<T[k]> }>;
diff --git a/tmp/agent-patch-flux-commit-7af773c0.1-of-1.2026-02-27__21-30-28__gpt-5-1-codex-mini/app/src/toZod.ts b/app/src/toZod.ts
index 9ae5fc5..11ae931 100644
--- a/tmp/agent-patch-flux-commit-7af773c0.1-of-1.2026-02-27__21-30-28__gpt-5-1-codex-mini/app/src/toZod.ts
+++ b/app/src/toZod.ts
@@ -16,6 +16,7 @@ export type toZod<T> = {
number: z.ZodNumber;
boolean: z.ZodBoolean;
date: z.ZodDate;
+ void: z.ZodVoid;
object: T extends { [k: string]: any } ? z.ZodObject<{ [k in keyof T]: toZod<T[k]> }> : never;
rest: never;
}[zodKey<T>];
@@ -24,6 +25,8 @@ type zodKey<T> = isAny<T> extends true
? 'any'
: equals<T, boolean> extends true //[T] extends [booleanUtil.Type]
? 'boolean'
+ : equals<T, void> extends true
+ ? 'void'
: [undefined] extends [T]
? 'optional'
: [null] extends [T]
@@ -41,31 +44,3 @@ type zodKey<T> = isAny<T> extends true
: T extends { [k: string]: any } //[T] extends [structUtil.Type]
? 'object'
: 'rest';
-
-type User = {
- name: string;
- age: number | undefined;
- active: boolean | null;
- posts: Post[];
-};
-
-type Post = {
- content: string;
- author: User;
-};
-
-const User: toZod<User> = z.lazy.object(() => ({
- name: z
- .string()
- .min(5)
- .max(2314)
- .refine(() => false, 'asdf'),
- age: z.number().optional(),
- active: z.boolean().nullable(),
- posts: z.array(
- z.object({
- content: z.string(),
- author: User,
- }),
- ),
-}));
diff --git a/tmp/agent-patch-flux-commit-7af773c0.1-of-1.2026-02-27__21-30-28__gpt-5-1-codex-mini/app/src/types/array.ts b/app/src/types/array.ts
index 1f64c2b..b29ffaf 100644
--- a/tmp/agent-patch-flux-commit-7af773c0.1-of-1.2026-02-27__21-30-28__gpt-5-1-codex-mini/app/src/types/array.ts
+++ b/app/src/types/array.ts
@@ -21,6 +21,10 @@ export class ZodArray<T extends z.ZodTypeAny> extends z.ZodType<T['_type'][], Zo
};
};
+ get element() {
+ return this._def.type;
+ }
+
optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);
diff --git a/app/src/types/void.ts b/app/src/types/void.ts
new file mode 100644
index 0000000..a5f421e
--- /dev/null
+++ b/app/src/types/void.ts
@@ -0,0 +1,23 @@
+import * as z from './base';
+import { ZodNull } from './null';
+import { ZodUndefined } from './undefined';
+import { ZodUnion } from './union';
+
+export interface ZodVoidDef extends z.ZodTypeDef {
+ t: z.ZodTypes.void;
+}
+
+export class ZodVoid extends z.ZodType<void, ZodVoidDef> {
+ toJSON = () => this._def;
+
+ optional: () => ZodUnion<[this, ZodUndefined]> = () =>
+ ZodUnion.create([this, ZodUndefined.create()] as [this, ZodUndefined]);
+
+ nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()] as [this, ZodNull]);
+
+ static create = (): ZodVoid => {
+ return new ZodVoid({
+ t: z.ZodTypes.void,
+ });
+ };
+}
diff --git a/app/src/userpost.ts b/app/src/userpost.ts
new file mode 100644
index 0000000..da948df
--- /dev/null
+++ b/app/src/userpost.ts
@@ -0,0 +1,39 @@
+import * as z from '.';
+import { util } from './helpers/util';
+
+export type Post = {
+ content: string;
+ author: User;
+};
+
+export type User = {
+ name: string;
+ age?: number | undefined;
+ active: boolean | null;
+ posts: Post[];
+};
+
+export const Post = z.lazy.object(() => ({
+ content: z.string(),
+ author: User,
+}));
+
+export const User = z.lazy.object(() => ({
+ name: z
+ .string()
+ .min(5)
+ .max(2314)
+ .refine(() => false, 'asdf'),
+ age: z.number().optional(),
+ active: z.boolean().nullable(),
+ posts: z.array(Post),
+}));
+
+type genUser = z.infer<typeof User>;
+type genPost = z.infer<typeof Post>;
+
+const t1: util.AssertEqual<User, genUser> = true;
+const t2: util.AssertEqual<Post, genPost> = true;
+
+export type { genUser, genPost };
+export { User, Post, t1, t2 };