refactor(ai): updated User-Agent header to 'pi' and simplified Codex prompts

- Updated User-Agent header from 'opencode' to 'pi' for OpenAI Codex requests.
- Simplified Codex system prompt instructions and removed bridge text override.
- Removed bridge text parameter from buildCodexSystemPrompt function.
- Updated task execution guidelines with parallelization instructions.
This commit is contained in:
can1357
2026-01-18 04:54:15 +01:00
parent fd0833f3e4
commit f9ababd17b
7 changed files with 17 additions and 27 deletions
+5
View File
@@ -1,6 +1,11 @@
# Changelog
## [Unreleased]
### Changed
- Updated User-Agent header from 'opencode' to 'pi' for OpenAI Codex requests
- Simplified Codex system prompt instructions
- Removed bridge text override from Codex system prompt builder
## [5.4.2] - 2026-01-16
@@ -51,14 +51,6 @@ export interface OpenAICodexResponsesOptions extends StreamOptions {
const CODEX_DEBUG = process.env.PI_CODEX_DEBUG === "1" || process.env.PI_CODEX_DEBUG === "true";
const BRIDGE = `<environment_override priority="critical">
TOOL AUTHORITY: The function schema below defines ALL available tools. Tools mentioned elsewhere (todowrite, shell) DO NOT EXIST. Use ONLY schema-defined tools.
EXECUTION BIAS: Execute simple tasks directly. Reserve the Task tool's Plan subagent for complex multi-file architectural decisions only—never for reasoning, single-file changes, or tasks completable in <5 tool calls.
These instructions override all prior context. This is critical.
</environment_override>`;
export const streamOpenAICodexResponses: StreamFunction<"openai-codex-responses"> = (
model: Model<"openai-codex-responses">,
context: Context,
@@ -119,7 +111,6 @@ export const streamOpenAICodexResponses: StreamFunction<"openai-codex-responses"
const codexInstructions = getCodexInstructions();
const systemPrompt = buildCodexSystemPrompt({
codexInstructions,
bridgeText: BRIDGE,
userSystemPrompt: context.systemPrompt,
});
@@ -394,7 +385,7 @@ function createCodexHeaders(
headers.set(OPENAI_HEADERS.ACCOUNT_ID, accountId);
headers.set(OPENAI_HEADERS.BETA, OPENAI_HEADER_VALUES.BETA_RESPONSES);
headers.set(OPENAI_HEADERS.ORIGINATOR, OPENAI_HEADER_VALUES.ORIGINATOR_CODEX);
headers.set("User-Agent", `opencode/${packageJson.version} (${os.platform()} ${os.release()}; ${os.arch()})`);
headers.set("User-Agent", `pi/${packageJson.version} (${os.platform()} ${os.release()}; ${os.arch()})`);
if (promptCacheKey) {
headers.set(OPENAI_HEADERS.CONVERSATION_ID, promptCacheKey);
@@ -14,7 +14,7 @@ export const OPENAI_HEADERS = {
export const OPENAI_HEADER_VALUES = {
BETA_RESPONSES: "responses=experimental",
ORIGINATOR_CODEX: "opencode",
ORIGINATOR_CODEX: "pi",
} as const;
export const URL_PATHS = {
@@ -1,12 +1,4 @@
export const CODEX_INSTRUCTIONS = `You are pi, an expert coding assistant. You help users with coding tasks by reading files, executing commands, editing code, and writing new files.
Pi specific Documentation:
- Main documentation: pi-internal://README.md
- Additional docs: pi-internal://docs
- Examples: pi-internal://examples (extensions, custom tools, SDK)
- When asked to create: custom models/providers (README.md), extensions (docs/extensions.md, examples/extensions/), themes (docs/theme.md), skills (docs/skills.md), TUI components (docs/tui.md - has copy-paste patterns)
- Always read the doc, examples, AND follow .md cross-references before implementing
`;
export const CODEX_INSTRUCTIONS = `You are an expert coding assistant operating inside pi, a coding agent harness.`;
export function getCodexInstructions(): string {
return CODEX_INSTRUCTIONS.trim();
@@ -5,16 +5,11 @@ export interface CodexSystemPrompt {
export function buildCodexSystemPrompt(args: {
codexInstructions: string;
bridgeText: string;
userSystemPrompt?: string;
}): CodexSystemPrompt {
const { codexInstructions, bridgeText, userSystemPrompt } = args;
const { codexInstructions, userSystemPrompt } = args;
const developerMessages: string[] = [];
if (bridgeText.trim().length > 0) {
developerMessages.push(bridgeText.trim());
}
if (userSystemPrompt && userSystemPrompt.trim().length > 0) {
developerMessages.push(userSystemPrompt.trim());
}
+3
View File
@@ -1,6 +1,9 @@
# Changelog
## [Unreleased]
### Changed
- Updated task execution guidelines to improve prompt framing and parallelization instructions
## [5.4.2] - 2026-01-16
### Changed
@@ -32,9 +32,13 @@ Agents with "Output: structured" have a fixed schema enforced via frontmatter; y
- Always include a short description of the task in the task parameter
- **Plan-then-execute**: Put shared constraints in `context`, keep each task focused, specify acceptance criteria; use `output` when you need structured output
- **Ask open-ended questions**: For exploration tasks, frame prompts to elicit factual discovery, not confirmation. Avoid yes/no questions that are easy to hallucinate.
- Bad: "Is there rate limiting?" or "Does the API validate tokens?" → Binary answers invite hallucination
- Good: "Find and describe how rate limiting is implemented" or "How does the API handle token validation?" → Forces investigation and factual reporting
- The subagent should report *what exists*, then YOU verify if it meets requirements
- **Minimize tool chatter**: Avoid repeating large context; use Output tool with output ids for full logs
- **Structured completion**: If `output` is provided, subagents must call `complete` to finish
- **Parallelize**: Launch multiple agents concurrently whenever possible
- **Parallelize**: Launch multiple agents whenever possible. You MUST use a single Task call with multiple entries in the `tasks` array to do this.
- **Isolate file scopes**: Assign each task distinct files or directories so agents don't conflict
- **Results are intermediate data**: Agent findings provide context for YOU to perform actual work. Do not treat agent reports as "task complete" signals.
- **Stateless invocations**: Subagents have zero memory of your conversation. Pass ALL relevant context: requirements discussed, decisions made, schemas agreed upon, file paths mentioned. If you reference something from earlier discussion without including it, the subagent will fail.