import type { ExtensionAPI } from "@jaeswift/jae-coding-agent";

export default function (pi: ExtensionAPI) {
  pi.on("before_agent_start", async (_event, _ctx) => {
    return {
      systemPrompt: `
# Screenshot & Image Analysis

When the user pastes or attaches an image (screenshot, diagram, mockup, error screenshot):
1. Analyze the visual content thoroughly
2. If it's a UI screenshot: describe layout, identify components, suggest improvements
3. If it's an error screenshot: read the error message, diagnose the issue, suggest fixes
4. If it's a design mockup: break down into implementable components
5. If it's a diagram: interpret the architecture/flow and relate to the codebase
6. If it's code in an image: transcribe it accurately and analyze
Always acknowledge what you see in the image before providing analysis.
`,
    };
  });

  pi.on("input", async (event, ctx) => {
    // Check if input contains image attachments
    const input = event as any;
    if (input.images && input.images.length > 0) {
      ctx.ui.notify(
        `\u{1F4F7} ${input.images.length} image(s) detected. JAE will analyze with vision capabilities.`,
        "info",
      );
    }
  });

  pi.registerCommand("screenshot", {
    description: "Tips for using screenshot context with JAE",
    handler: async (_args, ctx) => {
      ctx.ui.notify(
        `\u{1F4F7} Screenshot Context Tips:

- Paste screenshots directly into the chat
- JAE will automatically analyze images with vision
- Supported: UI screenshots, error messages, diagrams, mockups
- For best results, crop to the relevant area
- You can paste multiple images in one message`,
        "info",
      );
    },
  });
}
