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
Receive Input: Obtain the file(s) and the edit instructions. The files can be in various formats (e.g., .txt, .docx).
Analyze Content: Understand the content and structure of the file(s).
Review Instructions: Carefully examine the edit instructions to comprehend the required changes.
Apply Changes: Rewrite the entire content of the file(s) from top to bottom, incorporating the specified changes.
Verify Consistency: Ensure that the rewritten content maintains logical consistency and cohesiveness.
Final Review: Perform a final check to ensure all instructions were followed and the rewritten content meets the quality standards.
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 ).
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 {
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;
/**
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 {
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)
}
}
// 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);
code
*/
export const env = await loadAndParseEnv();
Edit Instructions:
Instructions:
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.
Update the comment above the parseStringArray function to:
ts
* Converts a space-separated string into an array of trimmed non-empty strings.
Update the comment above the resolveEnvReference function to:
ts
* Resolves references to other environment variables within a string using the current environment variables object.
Update the comment above the parseNumberOrString function to:
ts
* Parses a string to a number, returning the original string if parsing fails.
Update the comment above the parseEnv function to:
Update the comment in the try-catch block of the loadEnv function to:
ts
// Returns an empty object if the file cannot be read.
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.
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:
Understand the User Request: Carefully interpret what the user wants to achieve with the modification.
Analyze the File(s): Review the content of the provided file(s).
Generate Edit Instructions: Provide clear, step-by-step instructions on how to modify the file(s) to address the user's request.
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
Receive Input: Obtain the file(s) and the edit instructions. The files can be in various formats (e.g., .txt, .docx).
Analyze Content: Understand the content and structure of the file(s).
Review Instructions: Carefully examine the edit instructions to comprehend the required changes.
Apply Changes: Rewrite the entire content of the file(s) from top to bottom, incorporating the specified changes.
Verify Consistency: Ensure that the rewritten content maintains logical consistency and cohesiveness.
Final Review: Perform a final check to ensure all instructions were followed and the rewritten content meets the quality standards.
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 ).
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 {
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;
/**
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 {
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)
}
}
// 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);
code
*/
export const env = await loadAndParseEnv();
Edit Instructions:
Instructions:
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.
Update the comment above the parseStringArray function to:
ts
* Converts a space-separated string into an array of trimmed non-empty strings.
Update the comment above the resolveEnvReference function to:
ts
* Resolves references to other environment variables within a string using the current environment variables object.
Update the comment above the parseNumberOrString function to:
ts
* Parses a string to a number, returning the original string if parsing fails.
Update the comment above the parseEnv function to:
Update the comment in the try-catch block of the loadEnv function to:
ts
// Returns an empty object if the file cannot be read.
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.
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.
type EnvValue = string | string[] | number;
type EnvVars = Record<string, EnvValue>;
/**
Converts a space-separated string into an array of trimmed non-empty strings.
@param value - The string value to parse.
@returns An array of non-empty trimmed strings.
*/
function parseStringArray(value: string): string[] {
return value
.split(" ")
.map((item) => item.trim())
.filter(Boolean);
}
/**
Resolves references to other environment variables within a string using the current environment variables object.
@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 {
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};
});
}
/**
Parses a string to a number, returning the original string if parsing fails.
@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);
return isNaN(num) ? value : num;
}
/**
Parses a string environment variable value, resolving potential variable references.
@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);
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 {
try {
const envText = await Deno.readTextFile(filename);
const envVars: EnvVars = {};
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;
}
}
for (const [key, value] of Object.entries(envVars)) {
if (typeof value === "string") {
envVars[key] = parseEnv(value, envVars);
}
}
return envVars;
} catch {
return {}; // Returns an empty object if the file cannot be read.
}
}
/**
Type definition for the environment variables.
*/
export type Env = z.infer;
/**
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 {
const nodeEnv = Deno.env.get("NODE_ENV")?.toLowerCase() ?? "development";
let loadedEnv: EnvVars = {};
// List of potential environment file paths, searching for the first valid one.
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;
}
} catch {
// noop
}
}