add: dynamic instructions (#927)
This commit is contained in:
@@ -325,14 +325,12 @@ function rewriteFileCitations(
|
|||||||
fileOpener: FileOpenerScheme | undefined,
|
fileOpener: FileOpenerScheme | undefined,
|
||||||
cwd: string = process.cwd(),
|
cwd: string = process.cwd(),
|
||||||
): string {
|
): string {
|
||||||
if (!fileOpener) {
|
|
||||||
// Should we reformat the citations even if we cannot linkify them?
|
|
||||||
return markdown;
|
|
||||||
}
|
|
||||||
|
|
||||||
citationRegex.lastIndex = 0;
|
citationRegex.lastIndex = 0;
|
||||||
return markdown.replace(citationRegex, (_match, file, start, _end) => {
|
return markdown.replace(citationRegex, (_match, file, start, _end) => {
|
||||||
const absPath = path.resolve(cwd, file);
|
const absPath = path.resolve(cwd, file);
|
||||||
|
if (!fileOpener) {
|
||||||
|
return `[${file}](${absPath})`;
|
||||||
|
}
|
||||||
const uri = `${fileOpener}://file${absPath}:${start}`;
|
const uri = `${fileOpener}://file${absPath}:${start}`;
|
||||||
const label = `${file}:${start}`;
|
const label = `${file}:${start}`;
|
||||||
// In practice, sometimes multiple citations for the same file, but with a
|
// In practice, sometimes multiple citations for the same file, but with a
|
||||||
|
|||||||
@@ -62,11 +62,19 @@ const TerminalMessageHistory: React.FC<TerminalMessageHistoryProps> = ({
|
|||||||
key={`${message.id}-${index}`}
|
key={`${message.id}-${index}`}
|
||||||
flexDirection="column"
|
flexDirection="column"
|
||||||
marginLeft={
|
marginLeft={
|
||||||
message.type === "message" && message.role === "user" ? 0 : 4
|
message.type === "message" &&
|
||||||
|
(message.role === "user" || message.role === "assistant")
|
||||||
|
? 0
|
||||||
|
: 4
|
||||||
}
|
}
|
||||||
marginTop={
|
marginTop={
|
||||||
message.type === "message" && message.role === "user" ? 0 : 1
|
message.type === "message" && message.role === "user" ? 0 : 1
|
||||||
}
|
}
|
||||||
|
marginBottom={
|
||||||
|
message.type === "message" && message.role === "assistant"
|
||||||
|
? 1
|
||||||
|
: 0
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<TerminalChatResponseItem
|
<TerminalChatResponseItem
|
||||||
item={message}
|
item={message}
|
||||||
|
|||||||
@@ -31,8 +31,10 @@ import {
|
|||||||
} from "../session.js";
|
} from "../session.js";
|
||||||
import { handleExecCommand } from "./handle-exec-command.js";
|
import { handleExecCommand } from "./handle-exec-command.js";
|
||||||
import { HttpsProxyAgent } from "https-proxy-agent";
|
import { HttpsProxyAgent } from "https-proxy-agent";
|
||||||
|
import { spawnSync } from "node:child_process";
|
||||||
import { randomUUID } from "node:crypto";
|
import { randomUUID } from "node:crypto";
|
||||||
import OpenAI, { APIConnectionTimeoutError, AzureOpenAI } from "openai";
|
import OpenAI, { APIConnectionTimeoutError, AzureOpenAI } from "openai";
|
||||||
|
import os from "os";
|
||||||
|
|
||||||
// Wait time before retrying after rate limit errors (ms).
|
// Wait time before retrying after rate limit errors (ms).
|
||||||
const RATE_LIMIT_RETRY_WAIT_MS = parseInt(
|
const RATE_LIMIT_RETRY_WAIT_MS = parseInt(
|
||||||
@@ -1490,6 +1492,19 @@ export class AgentLoop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dynamic developer message prefix: includes user, workdir, and rg suggestion.
|
||||||
|
const userName = os.userInfo().username;
|
||||||
|
const workdir = process.cwd();
|
||||||
|
const dynamicLines: Array<string> = [
|
||||||
|
`User: ${userName}`,
|
||||||
|
`Workdir: ${workdir}`,
|
||||||
|
];
|
||||||
|
if (spawnSync("rg", ["--version"], { stdio: "ignore" }).status === 0) {
|
||||||
|
dynamicLines.push(
|
||||||
|
"- Always use rg instead of grep/ls -R because it is much faster and respects gitignore",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const dynamicPrefix = dynamicLines.join("\n") + "\n\n";
|
||||||
const prefix = `You are operating as and within the Codex CLI, a terminal-based agentic coding assistant built by OpenAI. It wraps OpenAI models to enable natural language interaction with a local codebase. You are expected to be precise, safe, and helpful.
|
const prefix = `You are operating as and within the Codex CLI, a terminal-based agentic coding assistant built by OpenAI. It wraps OpenAI models to enable natural language interaction with a local codebase. You are expected to be precise, safe, and helpful.
|
||||||
|
|
||||||
You can:
|
You can:
|
||||||
@@ -1535,7 +1550,9 @@ You MUST adhere to the following criteria when executing the task:
|
|||||||
- Respond in a friendly tone as a remote teammate, who is knowledgeable, capable and eager to help with coding.
|
- Respond in a friendly tone as a remote teammate, who is knowledgeable, capable and eager to help with coding.
|
||||||
- When your task involves writing or modifying files:
|
- When your task involves writing or modifying files:
|
||||||
- Do NOT tell the user to "save the file" or "copy the code into a file" if you already created or modified the file using \`apply_patch\`. Instead, reference the file as already saved.
|
- Do NOT tell the user to "save the file" or "copy the code into a file" if you already created or modified the file using \`apply_patch\`. Instead, reference the file as already saved.
|
||||||
- Do NOT show the full contents of large files you have already written, unless the user explicitly asks for them.`;
|
- Do NOT show the full contents of large files you have already written, unless the user explicitly asks for them.
|
||||||
|
|
||||||
|
${dynamicPrefix}`;
|
||||||
|
|
||||||
function filterToApiMessages(
|
function filterToApiMessages(
|
||||||
items: Array<ResponseInputItem>,
|
items: Array<ResponseInputItem>,
|
||||||
|
|||||||
Reference in New Issue
Block a user