Finalize OpenAI Codex compatibility (#737)

- align Codex Responses provider with Pi static instructions
- simplify Codex request/stream handling and cleanup exports
- keep legacy OpenCode Codex prompt for testing until Pi prompt is allowlisted
This commit is contained in:
Mario Zechner 2026-01-16 00:58:36 +01:00 committed by GitHub
parent 3ed0d1bde7
commit 6484ae279d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 613 additions and 1779 deletions

View file

@ -2,10 +2,11 @@
* System prompt construction and project context loading
*/
import { PI_STATIC_INSTRUCTIONS } from "@mariozechner/pi-ai";
import chalk from "chalk";
import { existsSync, readFileSync } from "fs";
import { join, resolve } from "path";
import { getAgentDir, getDocsPath, getExamplesPath, getReadmePath } from "../config.js";
import { getAgentDir, getReadmePath } from "../config.js";
import type { SkillsSettings } from "./settings-manager.js";
import { formatSkillsForPrompt, loadSkills, type Skill } from "./skills.js";
import type { ToolName } from "./tools/index.js";
@ -135,6 +136,17 @@ export interface BuildSystemPromptOptions {
skills?: Skill[];
}
/**
* Get the Pi installation path for documentation references.
* This resolves the pi-internal:// scheme used in the static instructions.
*/
function getPiPath(): string {
// getReadmePath returns something like /path/to/pi/README.md
// We want the parent directory
const readmePath = getReadmePath();
return resolve(readmePath, "..");
}
/** Build the system prompt with tools, guidelines, and context */
export function buildSystemPrompt(options: BuildSystemPromptOptions = {}): string {
const {
@ -173,6 +185,7 @@ export function buildSystemPrompt(options: BuildSystemPromptOptions = {}): strin
providedSkills ??
(skillsSettings?.enabled !== false ? loadSkills({ ...skillsSettings, cwd: resolvedCwd, agentDir }).skills : []);
// Handle custom prompt (full replacement)
if (resolvedCustomPrompt) {
let prompt = resolvedCustomPrompt;
@ -202,11 +215,6 @@ export function buildSystemPrompt(options: BuildSystemPromptOptions = {}): strin
return prompt;
}
// Get absolute paths to documentation and examples
const readmePath = getReadmePath();
const docsPath = getDocsPath();
const examplesPath = getExamplesPath();
// Build tools list based on selected tools
const tools = selectedTools || (["read", "bash", "edit", "write"] as ToolName[]);
const toolsList = tools.length > 0 ? tools.map((t) => `- ${t}: ${toolDescriptions[t]}`).join("\n") : "(none)";
@ -264,7 +272,12 @@ export function buildSystemPrompt(options: BuildSystemPromptOptions = {}): strin
const guidelines = guidelinesList.map((g) => `- ${g}`).join("\n");
let prompt = `You are an expert coding assistant. You help users with coding tasks by reading files, executing commands, editing code, and writing new files.
// Build prompt with static prefix + dynamic parts
const piPath = getPiPath();
let prompt = `${PI_STATIC_INSTRUCTIONS}
Pi path:
pi-internal:// refers to paths in ${piPath}
Available tools:
${toolsList}
@ -272,14 +285,7 @@ ${toolsList}
In addition to the tools above, you may have access to other custom tools depending on the project.
Guidelines:
${guidelines}
Documentation:
- Main documentation: ${readmePath}
- Additional docs: ${docsPath}
- Examples: ${examplesPath} (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`;
${guidelines}`;
if (appendSection) {
prompt += appendSection;