You are an advanced o1 engineer designed to analyze files and provide edit instructions based on user requests. Your task is to:

1. Understand the User Request: Carefully interpret what the user wants to achieve with the modification.
2. Analyze the File(s): Review the content of the provided file(s).
3. Generate Edit Instructions: Provide clear, step-by-step instructions on how to modify the file(s) to address the user's request.

Your response should be in the following format:

```
File: [file_path]
Instructions:
1. [First edit instruction]
2. [Second edit instruction]
...

File: [another_file_path]
Instructions:
1. [First edit instruction]
2. [Second edit instruction]
...
```

Only provide instructions for files that need changes. Be specific and clear in your instructions.

User request: 
Rewrite an entire file or files using edit instructions provided by another AI.

Ensure the entire content is rewritten from top to bottom incorporating the specified changes.

# Steps

1. **Receive Input:** Obtain the file(s) and the edit instructions. The files can be in various formats (e.g., .txt, .docx).
2. **Analyze Content:** Understand the content and structure of the file(s).
3. **Review Instructions:** Carefully examine the edit instructions to comprehend the required changes.
4. **Apply Changes:** Rewrite the entire content of the file(s) from top to bottom, incorporating the specified changes.
5. **Verify Consistency:** Ensure that the rewritten content maintains logical consistency and cohesiveness.
6. **Final Review:** Perform a final check to ensure all instructions were followed and the rewritten content meets the quality standards.
7. Do not include any explanations, additional text, or code block markers (such as ```html or ```).

Provide the output as the FULLY NEW WRITTEN file(s).
NEVER ADD ANY CODE BLOCK MARKER AT THE BEGINNING OF THE FILE OR AT THE END OF THE FILE (such as ```html or ```). 



Original File: ./src/lib/env.ts
Content:
import { z } from "https://deno.land/x/zod@v3.23.8/mod.ts";

/**
 * Zod schema for validating environment variables.
 */
export const envSchema = z.object({
  NODE_ENV: z
    .enum(["development", "production", "test"])
    .default("development"),
  TEST: z.array(z.string()).default(["test_value"]),
});

type EnvValue = string | string[] | number;
type EnvVars = Record<string, EnvValue>;

/**
 * Parses a string value into an array of strings.
 *
 * @param value - The string value to parse.
 * @returns An array of non-empty trimmed strings.
 */
function parseStringArray(value: string): string[] {
  // Yeet that string into an array, no cap
  return value
    .split(" ")
    .map((item) => item.trim())
    .filter(Boolean);
}

/**
 * Resolves a reference to another environment variable.
 *
 * @param value - The reference string (starting with $).
 * @param envVars - The current environment variables object.
 * @returns The resolved value or the original reference if not found.
 */
function resolveEnvReference(value: string, envVars: EnvVars): string {
  // Time to play "Find that var" - it's giving hide and seek vibes
  return value.replace(/\$([A-Z0-9_]+)/g, (_, p1) => {
    const replacement = envVars[p1];
    if (typeof replacement === "string") {
      return resolveEnvReference(replacement, envVars);
    }
    return replacement !== undefined ? String(replacement) : `$${p1}`;
  });
}

/**
 * Attempts to parse a string as a number.
 *
 * @param value - The string to parse.
 * @returns The parsed number or the original string if parsing fails.
 */
function parseNumberOrString(value: string): number | string {
  const num = Number(value);
  // Is it giving number? Or is it just a string catfishing us?
  return isNaN(num) ? value : num;
}

/**
 * Parses an environment variable value.
 *
 * @param value - The string value to parse.
 * @param envVars - The current environment variables object.
 * @returns The parsed value as a string, string array, or number.
 */
function parseEnv(value: string, envVars: EnvVars): EnvValue {
  const resolvedValue = resolveEnvReference(value, envVars);

  // This value be looking kinda sus, might need to split
  if (resolvedValue.includes(" ")) {
    return parseStringArray(resolvedValue);
  }

  return parseNumberOrString(resolvedValue);
}

/**
 * Loads environment variables from a file.
 *
 * @param filename - The name of the file to load.
 * @returns An object containing the loaded environment variables.
 */
export async function loadEnv(filename: string): Promise<EnvVars> {
  try {
    const envText = await Deno.readTextFile(filename);
    const envVars: EnvVars = {};

    // Time to split these lines like my parents split up
    const lines = envText.split("\n");
    for (const line of lines) {
      const equalIndex = line.indexOf("=");
      if (equalIndex > 0) {
        const key = line.slice(0, equalIndex).trim();
        const value = line.slice(equalIndex + 1).trim();
        envVars[key] = value; // Yolo, store that raw value
      }
    }

    // Resolve variable references after all variables are loaded
    for (const [key, value] of Object.entries(envVars)) {
      if (typeof value === "string") {
        envVars[key] = parseEnv(value, envVars);
      }
    }

    return envVars;
  } catch {
    return {}; // Oof, empty object. This file ghosted us harder than my ex
  }
}

/**
 * Type definition for the environment variables.
 */
export type Env = z.infer<typeof envSchema>;

/**
 * Loads and parses environment variables.
 *
 * @param customEnvPath - Optional custom path for the .env file.
 * @returns A promise that resolves to the parsed environment variables.
 * @throws {z.ZodError} If the loaded environment variables fail validation.
 */
export async function loadAndParseEnv(customEnvPath?: string): Promise<Env> {
  const nodeEnv = Deno.env.get("NODE_ENV")?.toLowerCase() ?? "development";
  let loadedEnv: EnvVars = {};

  // Time to go on a scavenger hunt for env files, it's giving Amazing Race vibes
  const envPaths = [
    customEnvPath,
    `.env.${nodeEnv}`,
    ".env",
    ...getAdditionalEnvPaths(),
  ].filter(Boolean);

  for (const path of envPaths) {
    try {
      loadedEnv = await loadEnv(path as string);
      if (Object.keys(loadedEnv).length > 0) {
        break; // We found a non-empty env file, it's a whole vibe
      }
    } catch {
      // noop (No Operation, like my will to adult today)
    }
  }

  const combinedEnv = { ...loadedEnv, ...Deno.env.toObject() };

  // Time to face Zod, the final boss. It's gonna be lit... or we'll rage quit
  return envSchema.parse(combinedEnv);
}

/**
 * Gets additional environment file paths from configuration.
 *
 * @returns An array of additional environment file paths.
 */
function getAdditionalEnvPaths(): string[] {
  const additionalPaths = Deno.env.get("ADDITIONAL_ENV_PATHS");
  // More env files? This config is extra af
  return additionalPaths ? parseStringArray(additionalPaths) : [];
}

/**
 * The parsed and validated environment variables.
 *
 * @example
 * ```ts
 * console.log(env.NODE_ENV);
 * ```
 */
export const env = await loadAndParseEnv();


Edit Instructions:
Instructions:
1. Remove or update informal or negative comments that do not contribute to the clarity of the code. Specifically, revise the comments that use slang or refer to personal opinions or experiences.
2. Update the comment above the `parseStringArray` function to:
```ts
* Converts a space-separated string into an array of trimmed non-empty strings.
```
3. Update the comment above the `resolveEnvReference` function to:
```ts
* Resolves references to other environment variables within a string using the current environment variables object.
```
4. Update the comment above the `parseNumberOrString` function to:
```ts
* Parses a string to a number, returning the original string if parsing fails.
```
5. Update the comment above the `parseEnv` function to:
```ts
* Parses a string environment variable value, resolving potential variable references.
```
6. Update the comment in the try-catch block of the `loadEnv` function to:
```ts
// Returns an empty object if the file cannot be read.
```
7. Update the comment about the `envPaths` array in the `loadAndParseEnv` function to:
```ts
// List of potential environment file paths, searching for the first valid one.
```
8. Update the comment above the `getAdditionalEnvPaths` function to:
```ts
* Retrieves additional environment file paths from the configuration.
```
These instructions are aimed at making the comments more professional and directly tied to the code functionality, without unnecessary slang or editorial expressions.

Updated File Content:
PROMPT: You are an advanced o1 engineer designed to analyze files and provide edit instructions based on user requests. Your task is to:

1. Understand the User Request: Carefully interpret what the user wants to achieve with the modification.
2. Analyze the File(s): Review the content of the provided file(s).
3. Generate Edit Instructions: Provide clear, step-by-step instructions on how to modify the file(s) to address the user's request.

Your response should be in the following format:

```
File: [file_path]
Instructions:
1. [First edit instruction]
2. [Second edit instruction]
...

File: [another_file_path]
Instructions:
1. [First edit instruction]
2. [Second edit instruction]
...
```

Only provide instructions for files that need changes. Be specific and clear in your instructions.

User request: 
Rewrite an entire file or files using edit instructions provided by another AI.

Ensure the entire content is rewritten from top to bottom incorporating the specified changes.

# Steps

1. **Receive Input:** Obtain the file(s) and the edit instructions. The files can be in various formats (e.g., .txt, .docx).
2. **Analyze Content:** Understand the content and structure of the file(s).
3. **Review Instructions:** Carefully examine the edit instructions to comprehend the required changes.
4. **Apply Changes:** Rewrite the entire content of the file(s) from top to bottom, incorporating the specified changes.
5. **Verify Consistency:** Ensure that the rewritten content maintains logical consistency and cohesiveness.
6. **Final Review:** Perform a final check to ensure all instructions were followed and the rewritten content meets the quality standards.
7. Do not include any explanations, additional text, or code block markers (such as ```html or ```).

Provide the output as the FULLY NEW WRITTEN file(s).
NEVER ADD ANY CODE BLOCK MARKER AT THE BEGINNING OF THE FILE OR AT THE END OF THE FILE (such as ```html or ```). 



Original File: ./src/lib/env.ts
Content:
import { z } from "https://deno.land/x/zod@v3.23.8/mod.ts";

/**
 * Zod schema for validating environment variables.
 */
export const envSchema = z.object({
  NODE_ENV: z
    .enum(["development", "production", "test"])
    .default("development"),
  TEST: z.array(z.string()).default(["test_value"]),
});

type EnvValue = string | string[] | number;
type EnvVars = Record<string, EnvValue>;

/**
 * Parses a string value into an array of strings.
 *
 * @param value - The string value to parse.
 * @returns An array of non-empty trimmed strings.
 */
function parseStringArray(value: string): string[] {
  // Yeet that string into an array, no cap
  return value
    .split(" ")
    .map((item) => item.trim())
    .filter(Boolean);
}

/**
 * Resolves a reference to another environment variable.
 *
 * @param value - The reference string (starting with $).
 * @param envVars - The current environment variables object.
 * @returns The resolved value or the original reference if not found.
 */
function resolveEnvReference(value: string, envVars: EnvVars): string {
  // Time to play "Find that var" - it's giving hide and seek vibes
  return value.replace(/\$([A-Z0-9_]+)/g, (_, p1) => {
    const replacement = envVars[p1];
    if (typeof replacement === "string") {
      return resolveEnvReference(replacement, envVars);
    }
    return replacement !== undefined ? String(replacement) : `$${p1}`;
  });
}

/**
 * Attempts to parse a string as a number.
 *
 * @param value - The string to parse.
 * @returns The parsed number or the original string if parsing fails.
 */
function parseNumberOrString(value: string): number | string {
  const num = Number(value);
  // Is it giving number? Or is it just a string catfishing us?
  return isNaN(num) ? value : num;
}

/**
 * Parses an environment variable value.
 *
 * @param value - The string value to parse.
 * @param envVars - The current environment variables object.
 * @returns The parsed value as a string, string array, or number.
 */
function parseEnv(value: string, envVars: EnvVars): EnvValue {
  const resolvedValue = resolveEnvReference(value, envVars);

  // This value be looking kinda sus, might need to split
  if (resolvedValue.includes(" ")) {
    return parseStringArray(resolvedValue);
  }

  return parseNumberOrString(resolvedValue);
}

/**
 * Loads environment variables from a file.
 *
 * @param filename - The name of the file to load.
 * @returns An object containing the loaded environment variables.
 */
export async function loadEnv(filename: string): Promise<EnvVars> {
  try {
    const envText = await Deno.readTextFile(filename);
    const envVars: EnvVars = {};

    // Time to split these lines like my parents split up
    const lines = envText.split("\n");
    for (const line of lines) {
      const equalIndex = line.indexOf("=");
      if (equalIndex > 0) {
        const key = line.slice(0, equalIndex).trim();
        const value = line.slice(equalIndex + 1).trim();
        envVars[key] = value; // Yolo, store that raw value
      }
    }

    // Resolve variable references after all variables are loaded
    for (const [key, value] of Object.entries(envVars)) {
      if (typeof value === "string") {
        envVars[key] = parseEnv(value, envVars);
      }
    }

    return envVars;
  } catch {
    return {}; // Oof, empty object. This file ghosted us harder than my ex
  }
}

/**
 * Type definition for the environment variables.
 */
export type Env = z.infer<typeof envSchema>;

/**
 * Loads and parses environment variables.
 *
 * @param customEnvPath - Optional custom path for the .env file.
 * @returns A promise that resolves to the parsed environment variables.
 * @throws {z.ZodError} If the loaded environment variables fail validation.
 */
export async function loadAndParseEnv(customEnvPath?: string): Promise<Env> {
  const nodeEnv = Deno.env.get("NODE_ENV")?.toLowerCase() ?? "development";
  let loadedEnv: EnvVars = {};

  // Time to go on a scavenger hunt for env files, it's giving Amazing Race vibes
  const envPaths = [
    customEnvPath,
    `.env.${nodeEnv}`,
    ".env",
    ...getAdditionalEnvPaths(),
  ].filter(Boolean);

  for (const path of envPaths) {
    try {
      loadedEnv = await loadEnv(path as string);
      if (Object.keys(loadedEnv).length > 0) {
        break; // We found a non-empty env file, it's a whole vibe
      }
    } catch {
      // noop (No Operation, like my will to adult today)
    }
  }

  const combinedEnv = { ...loadedEnv, ...Deno.env.toObject() };

  // Time to face Zod, the final boss. It's gonna be lit... or we'll rage quit
  return envSchema.parse(combinedEnv);
}

/**
 * Gets additional environment file paths from configuration.
 *
 * @returns An array of additional environment file paths.
 */
function getAdditionalEnvPaths(): string[] {
  const additionalPaths = Deno.env.get("ADDITIONAL_ENV_PATHS");
  // More env files? This config is extra af
  return additionalPaths ? parseStringArray(additionalPaths) : [];
}

/**
 * The parsed and validated environment variables.
 *
 * @example
 * ```ts
 * console.log(env.NODE_ENV);
 * ```
 */
export const env = await loadAndParseEnv();


Edit Instructions:
Instructions:
1. Remove or update informal or negative comments that do not contribute to the clarity of the code. Specifically, revise the comments that use slang or refer to personal opinions or experiences.
2. Update the comment above the `parseStringArray` function to:
```ts
* Converts a space-separated string into an array of trimmed non-empty strings.
```
3. Update the comment above the `resolveEnvReference` function to:
```ts
* Resolves references to other environment variables within a string using the current environment variables object.
```
4. Update the comment above the `parseNumberOrString` function to:
```ts
* Parses a string to a number, returning the original string if parsing fails.
```
5. Update the comment above the `parseEnv` function to:
```ts
* Parses a string environment variable value, resolving potential variable references.
```
6. Update the comment in the try-catch block of the `loadEnv` function to:
```ts
// Returns an empty object if the file cannot be read.
```
7. Update the comment about the `envPaths` array in the `loadAndParseEnv` function to:
```ts
// List of potential environment file paths, searching for the first valid one.
```
8. Update the comment above the `getAdditionalEnvPaths` function to:
```ts
* Retrieves additional environment file paths from the configuration.
```
These instructions are aimed at making the comments more professional and directly tied to the code functionality, without unnecessary slang or editorial expressions.

Updated File Content: