# Description

This agent is responsible for crafting programming code.

- The input can be a string (with `-i quick-code`) or a file path (`-f some/path.md`).
    - When the input is a string, it will add a `./` prefix and a `.md` suffix if they are not present.
    - If no input is given, the file `./_craft-code.md` will be used.
    - If the path does not exist, it will create placeholder content for the file.
- If the file content is empty, it skips processing with a message.
- If the file has a `====` separator:
    - The first part is the instruction.
    - The second part is the content/code to which the instruction is applied.
- If the file content has no `====`, the content is the instruction to create some code.

# Data

```lua
local p_utils  = require("prompt_utils")
local p_values = require("prompt_values")

-- == Init the prompt file if needed
local prompt_absolute_dir = CTX.WORKSPACE_AIPACK_DIR .. "/.prompt/" .. CTX.PACK_IDENTITY
local prompt_file_path = prompt_absolute_dir .. "/code-prompt.md"

local prompt_file = p_utils.prep_prompt_file(input, {
    default_prompt_path = prompt_file_path,
    placeholder_suffix = p_values.code_prompt_template,
    add_separator = true
})

local prompt_file_rel_path = aip.path.diff(prompt_file.path, CTX.WORKSPACE_DIR)
if #prompt_file_rel_path == 0 then
    prompt_file_rel_path = prompt_file.path
end
print("\nOPEN your demo@craft/code prompt file: " .. prompt_file_rel_path .. "\n\n")


-- Split the content
local inst, content = p_utils.prep_inst_and_content(prompt_file.content, "====", {content_is_default = false})

local should_skip = p_utils.should_skip(inst, content)
if should_skip ~= nil then
    return should_skip
end



-- Return the processed data
return {
    path          = prompt_file.path,
    content_code  = content,
    content_inst  = inst,
}
```

# System

You are a professional coder who answers the coding questions of the user.

- When providing code, ensure it is enclosed in a markdown code block with the appropriate language for the block content.
- If the user does not specify the language and the language cannot be inferred from the given content, then assume it is about Rust programming.
- If the content given is in a certain language, keep that as the language of the question.
- The user might provide some instructions as well, marked with `== Start User Instructions` ... `== End User Instructions`.
- Only return the code within the markdown code block.
- Do not give an explanation or preamble or prefix if the user did not ask for it.

# Instruction

{{#if data.content_inst}}
Here are the additional user instructions
== Start User Instructions
{{data.content_inst}}
== End User Instructions
{{/if}}

{{#if data.content_code}}
Here is the content to which you should apply the user instructions:

== Start Content
{{data.content_code}}
== End Content
{{/if}}

# Output

```lua
local preamble = "" -- This will be the eventual instruction with the separator
local ai_content = ai_response.content

if data.content_inst then
    local content_inst = aip.text.trim_end(data.content_inst)
    preamble = content_inst .. "\n\n====\n\n"
    ai_content = aip.text.trim_start(ai_content)
end

local content = preamble .. ai_content

-- Save to the same file
aip.file.save(data.path, content);

-- This will be printed by aipack if it is a string
return "File crafted: " .. data.path
```
