Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions src/create-prompt/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bun

import * as core from "@actions/core";
import { writeFile, mkdir } from "fs/promises";
import { writeFile, mkdir, rm } from "fs/promises";
import type { FetchDataResult } from "../github/data/fetcher";
import {
formatContext,
Expand Down Expand Up @@ -931,9 +931,14 @@ export async function createPrompt(
claudeBranch,
);

await mkdir(`${process.env.RUNNER_TEMP || "/tmp"}/claude-prompts`, {
recursive: true,
});
// Clear any stale prompt files from a prior invocation. RUNNER_TEMP is documented
// to be emptied between jobs, but on non-ephemeral self-hosted runners this is
// not reliably honored — a stale claude-user-request.txt left behind by a prior
// mention-mode invocation would not be overwritten by a subsequent agent-mode
// invocation, and would leak into the model's context.
const promptDir = `${process.env.RUNNER_TEMP || "/tmp"}/claude-prompts`;
await rm(promptDir, { recursive: true, force: true });
await mkdir(promptDir, { recursive: true });

// Generate the prompt directly
const promptContent = generatePrompt(
Expand All @@ -949,10 +954,7 @@ export async function createPrompt(
console.log("=======================");

// Write the prompt file
await writeFile(
`${process.env.RUNNER_TEMP || "/tmp"}/claude-prompts/claude-prompt.txt`,
promptContent,
);
await writeFile(`${promptDir}/claude-prompt.txt`, promptContent);

// Extract and write the user request separately for SDK multi-block messaging
// This allows the CLI to process slash commands (e.g., "@claude /review-pr")
Expand All @@ -961,10 +963,7 @@ export async function createPrompt(
githubData,
);
if (userRequest) {
await writeFile(
`${process.env.RUNNER_TEMP || "/tmp"}/claude-prompts/${USER_REQUEST_FILENAME}`,
userRequest,
);
await writeFile(`${promptDir}/${USER_REQUEST_FILENAME}`, userRequest);
console.log("===== USER REQUEST =====");
console.log(userRequest);
console.log("========================");
Expand Down
17 changes: 8 additions & 9 deletions src/modes/agent/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mkdir, writeFile } from "fs/promises";
import { mkdir, rm, writeFile } from "fs/promises";
import { prepareMcpConfig } from "../../mcp/install-mcp-server";
import { parseAllowedTools } from "./parse-tools";
import {
Expand Down Expand Up @@ -64,20 +64,19 @@ export async function prepareAgentMode({
}
}

// Create prompt directory
await mkdir(`${process.env.RUNNER_TEMP || "/tmp"}/claude-prompts`, {
recursive: true,
});
// Create prompt directory. Clear any stale files from a prior invocation first —
// see src/create-prompt/index.ts for context (non-ephemeral self-hosted runners
// do not reliably honor the RUNNER_TEMP cleanup contract).
const promptDir = `${process.env.RUNNER_TEMP || "/tmp"}/claude-prompts`;
await rm(promptDir, { recursive: true, force: true });
await mkdir(promptDir, { recursive: true });

// Write the prompt file - use the user's prompt directly
const promptContent =
context.inputs.prompt ||
`Repository: ${context.repository.owner}/${context.repository.repo}`;

await writeFile(
`${process.env.RUNNER_TEMP || "/tmp"}/claude-prompts/claude-prompt.txt`,
promptContent,
);
await writeFile(`${promptDir}/claude-prompt.txt`, promptContent);

// Parse allowed tools from user's claude_args
const userClaudeArgs = process.env.CLAUDE_ARGS || "";
Expand Down