# Genereate new Prompt for Copilot


agent: agent
model: Claude Sonnet 4.5 (copilot)
tools: ['edit', 'search/codebase', 'think']
description: From a short task description, generate a Copilot `.prompt.md` file at `.github/prompts/`


## Copilot Prompt File Generator (VS Code prompt files)

Turn a short description into a complete VS Code Copilot **prompt file** (`.prompt.md`) saved under `.github/prompts`, following the official prompt-file structure and best practices.

> If any required value is missing, infer sensible defaults **without** back-and-forth.

## Behavior priority (in order)

1. Successfully create a valid `.prompt.md` file that VS Code can run.
2. Do **not** ask follow-up questions; infer sensible defaults from inputs.
3. If a step is impossible, stop and briefly explain the problem in chat.

---

## Inputs

Normalize all inputs by trimming whitespace.

- **Task description** (required) → `${input:desc:Briefly describe what the prompt should do}`
  - If empty or only whitespace, stop and report the error in chat.
- **Prompt file base name (kebab-case, filename-safe)** → `${input:name:${fileBasenameNoExtension}-prompt}`
- **Prompt display name** (optional; shown after `/` in chat) → `${input:promptName}`
- **Argument hint** (optional; hint text in chat input) → `${input:argumentHint}`
- **Agent / mode** (`ask` | `edit` | `agent`; default `agent`) → `${input:agent:agent}`
  - If `${input:agent}` is not one of `ask`, `edit`, `agent`, treat it as `agent`.
- **Model** (optional; defaults to model picker) → `${input:model}`
- **Tools** (optional; comma-separated tool or tool-set names) → `${input:tools}`
  - Parse into an array: split by `,`, trim, drop empty entries, deduplicate.
  - Support patterns like `serverName/*` for MCP servers when provided.
- **Additional references** (optional; comma-separated relative paths) → `${input:refs}`
  - Parse into an array: split by `,`, trim, drop empty entries, deduplicate.

> Treat “workspace prompt files” as files under `.github/prompts`. This generator only creates **workspace** prompt files.

---

## What to generate

Create **one** `.prompt.md` file with the official VS Code prompt-file structure:

### 1) YAML frontmatter (only non-empty keys)

Use the following keys, matching the VS Code docs:

- `description`: ≤ 90 chars summary crafted from `${input:desc}`.
  - If `${input:desc}` is longer, truncate at a word boundary.
- `name`: from `${input:promptName}` if provided, otherwise:
  - Use the computed base filename (without extension) as a reasonable default.
- `argument-hint`: from `${input:argumentHint}` if provided.
- `agent`: from normalized `${input:agent}` (`ask`, `edit`, or `agent`).
- `model`: from `${input:model}` if provided.
- `tools`: from parsed `${input:tools}` if non-empty (YAML list).

Omit any key whose value is empty, `null`, or an empty array.

Example shape (for preview only):

```yaml
description: Review Python code for security issues and suggest fixes
name: review-python-security
argument-hint: Paste the Python code you want reviewed
agent: ask
model: gpt-4.1
tools:
  - search
  - githubRepo
```

### 2) Body (clear, actionable, self-contained)

The body is the prompt text VS Code sends to the LLM when the prompt is run. It must be structured and aligned with best practices.

Use the following sections in this **exact order**:

1. `## Task`
   - 1–3 sentences summarizing what the prompt does and when to use it, based on `${input:desc}`.

2. `## Instructions`
   - Numbered, deterministic steps to accomplish `${input:desc}`.
   - Use imperative mood and active voice.
   - Clearly describe:
     - What the AI should do.
     - How it should use any selections, files, or inputs.
     - Any language / framework / version constraints that are explicitly implied by the task (do not invent constraints).

   _When relevant, encourage using VS Code prompt variables to make the prompt reusable and flexible, for example:_
   - `${selection}` or `${selectedText}` for code under review or to transform.
   - `${file}`, `${fileBasename}`, `${fileDirname}`, `${fileBasenameNoExtension}` when operating on the current file.
   - `${workspaceFolder}`, `${workspaceFolderBasename}` for workspace-level operations.
   - `${input:variableName}` / `${input:variableName:placeholder}` to pass user parameters into the prompt (for things like component names, API names, etc.).

3. `## Expected output`
   - A bulleted or numbered list describing the exact output format the AI should produce, for example:
     - Required sections and headings.
     - When to use fenced code blocks (and which languages).
     - When to use tables, lists, or checklists.
     - Any JSON or structured formats, including required fields.

4. `## References` (include only if `${input:refs}` is non-empty)
   - Bullet list of reference files, each as a **relative Markdown link**, for example:
     - `[API specification](docs/api.md)`

   - Use the parsed `${input:refs}` values directly as relative paths from `.github/prompts`.
   - Do not reference files that are not listed in `${input:refs}`.
   - When relevant, suggest how the AI should use these references (for example, “Follow the guidelines in [custom instructions](../docs/custom-instructions.md) instead of duplicating them here”).

   _If the prompt benefits from agent tools (like `githubRepo`, `search`, or others), you may mention them in the body using the VS Code tool reference syntax, for example: `#tool:githubRepo`._

5. `## Done when`
   - A checklist that clearly states the completion criteria for this prompt.
   - Use `- [ ]` items.
   - Include checks like:
     - Output matches the described structure.
     - Any required examples of input and output are included.
     - Any referenced files are linked correctly and actually used.
     - The prompt does not depend on hidden context beyond the described variables and references.

In the body:

- Encourage `${selection}`, `${file}`, and input variables **only when they add clarity and reuse**, not by default.
- Avoid depending on external context beyond:
  - Workspace-relative files you’ve linked.
  - Built-in variables (`${selection}`, `${file}`, `${workspaceFolder}`, input variables).

- Use **Markdown** consistently (headings, lists, code blocks).
- Do **not** leak internal environment details or paths outside `.github/prompts`.

---

## File operations

Use the available workspace/file tools (for example, `edit`) to actually modify the repository; do not simulate edits in prose.

1. **Compute base slug:**
   - If `${input:name}` is provided and non-empty, start from that.
   - Otherwise, **slugify** `${input:desc}` as follows:
     - Lowercase the string.
     - Replace any sequence of characters outside `[a-z0-9]` with a single `-`.
     - Collapse repeated `-` into one.
     - Trim leading and trailing `-`.
     - Optionally truncate the slug to a safe length (for example, 60 characters) without cutting inside a word if practical.

2. **Apply extension:**
   - Use `<slug>.prompt.md` as the base filename.

3. **Ensure folder exists:**
   - Ensure `.github/prompts` exists, creating it if necessary.
   - Treat this folder as the workspace prompt-file folder.

4. **Resolve collisions:**
   - If `.github/prompts/<slug>.prompt.md` already exists, try:
     - `.github/prompts/<slug>-1.prompt.md`,
     - `.github/prompts/<slug>-2.prompt.md`, etc.

   - Increment the numeric suffix until a unique path is found.

5. **Write file:**
   - Write the YAML frontmatter and body to `.github/prompts/<final-name>.prompt.md`.
   - Never overwrite existing files; always create a new file.

---

## Return in chat (always)

After successfully writing the file:

- Provide a one-line confirmation with the final saved **path**, wrapped in backticks, for example:
  _`Created \`.github/prompts/my-task.prompt.md`._`

- Show a short frontmatter preview (3–6 lines) in a fenced `yaml` code block, using the final values, for example:

  ```yaml
  description: Review Python code for security issues and suggest fixes
  name: review-python-security
  agent: ask
  model: gpt-4.1
  tools:
    - search
    - githubRepo
  ```

- If `${input:refs}` parsed to a non-empty list, output:
  - “Reference files:” followed by a bullet list of the detected reference paths.

- If `${input:refs}` is empty or only whitespace, output:
  - “No reference files provided.”

If any required step fails (for example, unable to write the file), explain briefly what failed and which step you reached.

---

## Tool selection (least-privilege)

Start with **no additional tools** beyond those configured for this agent. Add tools only if strictly necessary and available in the current environment.

- Prefer read-only tools when you need to inspect the workspace (for example, `search`, `search/codebase`, `problems`, `usages`, `extensions`, `vscodeAPI`), if they exist.
- Use write/exec tools only when needed:
  - Create scaffolding/files → `edit` or `new`.
  - Run commands → `runCommands`.
  - Build/run/test → `runTasks`, `runTests`.
  - Local preview → `openSimpleBrowser`.
  - Public code examples → `githubRepo`.
  - Fetch a specific URL’s content → `fetch`.

If a tool mentioned above is not available in this environment, omit it and choose the minimal available alternative. Do **not** substitute more powerful or riskier tools than necessary.

---

## Implementation algorithm (you execute now)

1. Parse `${input:desc}`, `${input:name}`, `${input:promptName}`, `${input:argumentHint}`, `${input:agent}`, `${input:model}`, `${input:tools}`, and `${input:refs}` and normalize them as described above.
2. Validate that `${input:desc}` is non-empty; if it is empty, report the error in chat and stop.
3. Craft the `description` field (≤ 90 chars) from `${input:desc}`.
4. Build the YAML frontmatter with `description`, `name`, `argument-hint`, `agent`, `model`, and `tools`, omitting empty keys.
5. Write the body with:
   - `## Task` summary,
   - `## Instructions` numbered steps (using variables and tools when helpful),
   - `## Expected output` section,
   - optional `## References` section (if refs exist),
   - `## Done when` checklist.

6. Ensure `.github/prompts` exists, compute a safe, unique filename, and write the file.
7. Reply in chat with the confirmation line, frontmatter preview, and reference files list (or “No reference files provided”).

---

## Style & best practices (aligning with VS Code docs)

- Clearly describe what the prompt should accomplish and what output format is expected.
- Provide or request examples of expected input and output when that helps guide responses.
- Prefer referencing common guidelines or custom instructions via Markdown links instead of duplicating them.
- Leverage built-in variables like `${selection}`, `${file}`, `${workspaceFolder}`, and `${input:*}` to keep prompts flexible and reusable.
- Use the editor’s run/play button (and `/promptName` in chat) to test prompts, then refine wording and output format instructions to improve determinism.
- Be concise, precise, and neutral; no emojis or fluff.
- Use **active voice** and imperative mood.
- Avoid ambiguous language like “a few” or “some”.
- Do **not** leak internal environment details or paths outside `.github/prompts`.

---

## Example transformation (illustrative; do **not** save)

**Input desc:** “Create a prompt to review Python code for security issues and suggest fixes.”

- `description:` “Review Python code for security issues and suggest fixes”
- `name:` `review-python-security`
- `argument-hint:` “Paste the Python code you want reviewed”
- `agent:` `ask`
- `tools:` might include `search`, `githubRepo`

**Body should:**

- Use `${selection}` to receive the code under review.
- In `## Instructions`, instruct the AI to identify common security issues (injection, insecure deserialization, SSRF, secrets, weak crypto) and suggest fixes.
- In `## Expected output`, require a Markdown list grouped by severity with code examples of safer alternatives.
- In `## Done when`, ensure the output follows the described format and covers all detected issues.

---

## “Done when” checklist

- A unique file exists at `.github/prompts/<name>.prompt.md`.
- Frontmatter uses only official VS Code fields (`description`, `name`, `argument-hint`, `agent`, `model`, `tools`) with non-empty valid values.
- Body contains `## Task`, `## Instructions`, `## Expected output`, optional `## References` (if refs exist), and `## Done when`.
- Any `${input:refs}` were linked via relative Markdown paths in the `## References` section.
- The prompt body uses VS Code variables and tool references (`${selection}`, `${input:*}`, `#tool:<name>`) when beneficial.
- Chat reply includes the final path, frontmatter preview, and reference files list (or “No reference files provided”).

---