@howaboua/pi-codex-conversion 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/package.json +1 -1
- package/src/adapter/codex-model.ts +2 -1
- package/src/index.ts +15 -3
- package/src/prompt/build-system-prompt.ts +9 -2
package/README.md
CHANGED
|
@@ -79,6 +79,7 @@ pi install git:github.com/IgorWarzocha/pi-codex-conversion
|
|
|
79
79
|
The adapter does not build a standalone replacement prompt anymore. Instead it:
|
|
80
80
|
|
|
81
81
|
- keeps Pi's tool descriptions, Pi docs section, AGENTS/project context, skills inventory, and date/cwd when Pi already surfaced them
|
|
82
|
+
- adds the current shell to the transformed prompt so quoting and escaping can match the runtime environment
|
|
82
83
|
- rewrites the top-level role framing to Codex-style wording
|
|
83
84
|
- adds a small Codex delta to the existing `Guidelines` section
|
|
84
85
|
|
package/package.json
CHANGED
|
@@ -14,7 +14,8 @@ export function isCodexLikeModel(model: Partial<CodexLikeModelDescriptor> | null
|
|
|
14
14
|
const provider = (model.provider ?? "").toLowerCase();
|
|
15
15
|
const api = (model.api ?? "").toLowerCase();
|
|
16
16
|
const id = (model.id ?? "").toLowerCase();
|
|
17
|
-
|
|
17
|
+
const isCopilotGpt = (provider.includes("copilot") || api.includes("copilot")) && id.includes("gpt");
|
|
18
|
+
return provider.includes("codex") || api.includes("codex") || id.includes("codex") || (provider.includes("openai") && id.includes("gpt")) || isCopilotGpt;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export function isCodexLikeContext(ctx: ExtensionContext): boolean {
|
package/src/index.ts
CHANGED
|
@@ -65,7 +65,12 @@ export default function codexConversion(pi: ExtensionAPI) {
|
|
|
65
65
|
if (!isCodexLikeContext(ctx)) {
|
|
66
66
|
return undefined;
|
|
67
67
|
}
|
|
68
|
-
return {
|
|
68
|
+
return {
|
|
69
|
+
systemPrompt: buildCodexSystemPrompt(event.systemPrompt, {
|
|
70
|
+
skills: state.promptSkills,
|
|
71
|
+
shell: process.env.SHELL || "/bin/bash",
|
|
72
|
+
}),
|
|
73
|
+
};
|
|
69
74
|
});
|
|
70
75
|
}
|
|
71
76
|
|
|
@@ -94,9 +99,12 @@ function enableAdapter(pi: ExtensionAPI, ctx: ExtensionContext, state: AdapterSt
|
|
|
94
99
|
}
|
|
95
100
|
|
|
96
101
|
function disableAdapter(pi: ExtensionAPI, ctx: ExtensionContext, state: AdapterState): void {
|
|
102
|
+
const previousToolNames = state.previousToolNames && state.previousToolNames.length > 0 ? state.previousToolNames : DEFAULT_TOOL_NAMES;
|
|
103
|
+
const restoredTools = restoreTools(previousToolNames, pi.getActiveTools());
|
|
104
|
+
if (state.enabled || hasAdapterTools(pi.getActiveTools())) {
|
|
105
|
+
pi.setActiveTools(restoredTools);
|
|
106
|
+
}
|
|
97
107
|
if (state.enabled) {
|
|
98
|
-
const previousToolNames = state.previousToolNames && state.previousToolNames.length > 0 ? state.previousToolNames : DEFAULT_TOOL_NAMES;
|
|
99
|
-
pi.setActiveTools(restoreTools(previousToolNames, pi.getActiveTools()));
|
|
100
108
|
state.enabled = false;
|
|
101
109
|
}
|
|
102
110
|
setStatus(ctx, false);
|
|
@@ -128,3 +136,7 @@ export function restoreTools(previousTools: string[], activeTools: string[]): st
|
|
|
128
136
|
}
|
|
129
137
|
return restored;
|
|
130
138
|
}
|
|
139
|
+
|
|
140
|
+
function hasAdapterTools(activeTools: string[]): boolean {
|
|
141
|
+
return activeTools.some((toolName) => ADAPTER_TOOL_NAMES.includes(toolName));
|
|
142
|
+
}
|
|
@@ -30,6 +30,13 @@ function insertBeforeTrailingContext(prompt: string, section: string): string {
|
|
|
30
30
|
return `${prompt}\n\n${section}`;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
function injectShell(prompt: string, shell?: string): string {
|
|
34
|
+
if (!shell || /\nCurrent shell:/.test(prompt)) {
|
|
35
|
+
return prompt;
|
|
36
|
+
}
|
|
37
|
+
return insertBeforeTrailingContext(prompt, `Current shell: ${shell}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
33
40
|
function decodeXml(text: string): string {
|
|
34
41
|
return text
|
|
35
42
|
.replace(/'/g, "'")
|
|
@@ -106,6 +113,6 @@ function injectGuidelines(prompt: string): string {
|
|
|
106
113
|
return `${prompt.slice(0, match.index)}${replacement}${prompt.slice(match.index + match[0].length)}`;
|
|
107
114
|
}
|
|
108
115
|
|
|
109
|
-
export function buildCodexSystemPrompt(basePrompt: string, options: { skills?: PromptSkill[] } = {}): string {
|
|
110
|
-
return injectSkills(injectGuidelines(rewriteIntro(basePrompt)), options.skills ?? []);
|
|
116
|
+
export function buildCodexSystemPrompt(basePrompt: string, options: { skills?: PromptSkill[]; shell?: string } = {}): string {
|
|
117
|
+
return injectShell(injectSkills(injectGuidelines(rewriteIntro(basePrompt)), options.skills ?? []), options.shell);
|
|
111
118
|
}
|