@howaboua/pi-codex-conversion 1.5.5-dev.25.f80a775 → 1.5.5
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/package.json +1 -1
- package/src/adapter/activation.ts +0 -1
- package/src/adapter/config.ts +0 -24
- package/src/adapter/provider-request.ts +2 -4
- package/src/adapter/tool-set.ts +1 -2
- package/src/codex-settings/command.ts +3 -16
- package/src/codex-settings/ui.ts +48 -126
- package/src/index.ts +18 -34
- package/src/providers/openai-codex-custom-provider.ts +1 -1
- package/src/providers/openai-responses-shared.ts +0 -2
- package/vendor/apply-patch/win32-arm64/apply_patch.exe +0 -0
- package/vendor/apply-patch/win32-x64/apply_patch.exe +0 -0
- package/src/adapter/compact-client.ts +0 -257
- package/src/adapter/compaction-output.ts +0 -80
- package/src/adapter/compaction-runtime.ts +0 -272
- package/src/adapter/compaction.ts +0 -261
- package/src/adapter/context-filter.ts +0 -20
- package/src/adapter/details-store.ts +0 -151
- package/src/adapter/payload-rewrite.ts +0 -550
- package/src/adapter/serializer.ts +0 -288
- package/src/adapter/types.ts +0 -220
package/package.json
CHANGED
|
@@ -77,7 +77,6 @@ function getStatusConfig(ctx: ExtensionContext, config: CodexConversionConfig):
|
|
|
77
77
|
fast: showOpenAICodexFlags && config.fast,
|
|
78
78
|
webSearch: showOpenAICodexFlags && config.webSearch && supportsNativeWebSearch(ctx.model),
|
|
79
79
|
imageGeneration: showOpenAICodexFlags && config.imageGeneration && supportsNativeImageGeneration(ctx.model),
|
|
80
|
-
compaction: { enabled: Boolean(config.responsesCompaction), model: config.compactionModel, reasoning: config.compactionReasoning },
|
|
81
80
|
...(showResponsesVerbosity ? { verbosity: config.verbosity } : {}),
|
|
82
81
|
};
|
|
83
82
|
}
|
package/src/adapter/config.ts
CHANGED
|
@@ -3,18 +3,10 @@ import { dirname, join } from "node:path";
|
|
|
3
3
|
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
|
|
5
5
|
export type CodexVerbosity = "low" | "medium" | "high";
|
|
6
|
-
export type CompactionModel = "gpt-5.5" | "gpt-5.3-codex-spark" | "gpt-5.4-mini";
|
|
7
|
-
export type CompactionReasoning = "current" | "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
8
|
-
|
|
9
|
-
export const COMPACTION_MODELS: readonly CompactionModel[] = ["gpt-5.5", "gpt-5.3-codex-spark", "gpt-5.4-mini"];
|
|
10
|
-
export const COMPACTION_REASONING_LEVELS: readonly CompactionReasoning[] = ["current", "minimal", "low", "medium", "high", "xhigh"];
|
|
11
6
|
|
|
12
7
|
export interface CodexConversionConfig {
|
|
13
8
|
fast: boolean;
|
|
14
9
|
imageGeneration: boolean;
|
|
15
|
-
compactionModel: CompactionModel;
|
|
16
|
-
compactionReasoning: CompactionReasoning;
|
|
17
|
-
responsesCompaction?: boolean;
|
|
18
10
|
statusLine: boolean;
|
|
19
11
|
useOnAllModels: boolean;
|
|
20
12
|
webSearch: boolean;
|
|
@@ -25,9 +17,6 @@ export const CODEX_CONVERSION_CONFIG_BASENAME = "pi-codex-conversion.json";
|
|
|
25
17
|
export const DEFAULT_CODEX_CONVERSION_CONFIG: CodexConversionConfig = {
|
|
26
18
|
fast: false,
|
|
27
19
|
imageGeneration: true,
|
|
28
|
-
compactionModel: "gpt-5.5",
|
|
29
|
-
compactionReasoning: "current",
|
|
30
|
-
responsesCompaction: false,
|
|
31
20
|
statusLine: true,
|
|
32
21
|
useOnAllModels: false,
|
|
33
22
|
webSearch: true,
|
|
@@ -44,16 +33,6 @@ export function normalizeCodexVerbosity(value: unknown): CodexVerbosity | undefi
|
|
|
44
33
|
return normalized === "low" || normalized === "medium" || normalized === "high" ? normalized : undefined;
|
|
45
34
|
}
|
|
46
35
|
|
|
47
|
-
export function normalizeCompactionModel(value: unknown): CompactionModel | undefined {
|
|
48
|
-
if (typeof value !== "string") return undefined;
|
|
49
|
-
return (COMPACTION_MODELS as readonly string[]).includes(value) ? (value as CompactionModel) : undefined;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function normalizeCompactionReasoning(value: unknown): CompactionReasoning | undefined {
|
|
53
|
-
if (typeof value !== "string") return undefined;
|
|
54
|
-
return (COMPACTION_REASONING_LEVELS as readonly string[]).includes(value) ? (value as CompactionReasoning) : undefined;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
36
|
export function getCodexConversionConfigPath(agentDir: string = getAgentDir()): string {
|
|
58
37
|
return join(agentDir, CODEX_CONVERSION_CONFIG_BASENAME);
|
|
59
38
|
}
|
|
@@ -70,9 +49,6 @@ export function readCodexConversionConfig(configPath: string = getCodexConversio
|
|
|
70
49
|
return {
|
|
71
50
|
fast: typeof parsed.fast === "boolean" ? parsed.fast : DEFAULT_CODEX_CONVERSION_CONFIG.fast,
|
|
72
51
|
imageGeneration: typeof parsed.imageGeneration === "boolean" ? parsed.imageGeneration : DEFAULT_CODEX_CONVERSION_CONFIG.imageGeneration,
|
|
73
|
-
compactionModel: normalizeCompactionModel(parsed.compactionModel) ?? DEFAULT_CODEX_CONVERSION_CONFIG.compactionModel,
|
|
74
|
-
compactionReasoning: normalizeCompactionReasoning(parsed.compactionReasoning) ?? DEFAULT_CODEX_CONVERSION_CONFIG.compactionReasoning,
|
|
75
|
-
responsesCompaction: typeof parsed.responsesCompaction === "boolean" ? parsed.responsesCompaction : DEFAULT_CODEX_CONVERSION_CONFIG.responsesCompaction,
|
|
76
52
|
statusLine: typeof parsed.statusLine === "boolean" ? parsed.statusLine : DEFAULT_CODEX_CONVERSION_CONFIG.statusLine,
|
|
77
53
|
useOnAllModels: typeof parsed.useOnAllModels === "boolean" ? parsed.useOnAllModels : DEFAULT_CODEX_CONVERSION_CONFIG.useOnAllModels,
|
|
78
54
|
webSearch: typeof parsed.webSearch === "boolean" ? parsed.webSearch : DEFAULT_CODEX_CONVERSION_CONFIG.webSearch,
|
|
@@ -5,9 +5,8 @@ import type { AdapterState } from "./state.ts";
|
|
|
5
5
|
import { rewriteNativeImageGenerationTool } from "../tools/image-generation-tool.ts";
|
|
6
6
|
import { rewriteNativeWebSearchTool } from "../tools/web-search-tool.ts";
|
|
7
7
|
import { shouldUseCodexAdapter } from "./activation.ts";
|
|
8
|
-
import { rewriteCodexCompactedProviderRequest } from "./compaction.ts";
|
|
9
8
|
|
|
10
|
-
export
|
|
9
|
+
export function rewriteCodexProviderRequest(payload: unknown, ctx: ExtensionContext, state: AdapterState): unknown | undefined {
|
|
11
10
|
if (!shouldUseCodexAdapter(ctx, state.config) || (!isOpenAICodexContext(ctx) && !isResponsesContext(ctx))) {
|
|
12
11
|
return undefined;
|
|
13
12
|
}
|
|
@@ -17,9 +16,8 @@ export async function rewriteCodexProviderRequest(payload: unknown, ctx: Extensi
|
|
|
17
16
|
const imageGenerationPayload = isOpenAICodex && state.config.imageGeneration
|
|
18
17
|
? rewriteNativeImageGenerationTool(webSearchPayload, ctx.model)
|
|
19
18
|
: webSearchPayload;
|
|
20
|
-
|
|
19
|
+
return applyCodexRequestParams(imageGenerationPayload, state.config, {
|
|
21
20
|
serviceTier: isOpenAICodex,
|
|
22
21
|
verbosity: true,
|
|
23
22
|
});
|
|
24
|
-
return (await rewriteCodexCompactedProviderRequest(configuredPayload, ctx, state)) ?? configuredPayload;
|
|
25
23
|
}
|
package/src/adapter/tool-set.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
export const STATUS_KEY = "codex-adapter";
|
|
2
2
|
export const STATUS_TEXT = "\u001b[38;2;0;76;255mCodex adapter\u001b[0m";
|
|
3
3
|
|
|
4
|
-
export function buildStatusText(options: { verbosity?: string; webSearch: boolean; imageGeneration: boolean; fast: boolean; useOnAllModels: boolean
|
|
4
|
+
export function buildStatusText(options: { verbosity?: string; webSearch: boolean; imageGeneration: boolean; fast: boolean; useOnAllModels: boolean }): string {
|
|
5
5
|
const extras = [
|
|
6
6
|
options.useOnAllModels ? "all models" : undefined,
|
|
7
7
|
options.webSearch ? "web search" : undefined,
|
|
8
8
|
options.imageGeneration ? "image gen" : undefined,
|
|
9
|
-
options.compaction?.enabled ? `compact ${options.compaction.model}/${options.compaction.reasoning}` : undefined,
|
|
10
9
|
options.fast ? "fast" : undefined,
|
|
11
10
|
]
|
|
12
11
|
.filter(Boolean)
|
|
@@ -9,8 +9,7 @@ import { syncAdapter } from "../adapter/activation.ts";
|
|
|
9
9
|
import type { AdapterState } from "../adapter/state.ts";
|
|
10
10
|
import { openCodexSettingsScreen } from "./ui.ts";
|
|
11
11
|
|
|
12
|
-
const CODEX_COMMAND_COMPLETIONS = ["all", "status", "fast", "search", "image", "
|
|
13
|
-
const CODEX_USAGE = "Usage: /codex, /codex all, /codex status, /codex fast, /codex search, /codex image, /codex compact, /codex low|medium|high";
|
|
12
|
+
const CODEX_COMMAND_COMPLETIONS = ["all", "status", "fast", "search", "image", "low", "medium", "high"] as const;
|
|
14
13
|
|
|
15
14
|
export function registerCodexCommand(pi: ExtensionAPI, state: AdapterState, onConfigApplied?: (config: CodexConversionConfig) => void): void {
|
|
16
15
|
function saveAndApply(ctx: ExtensionContext, nextConfig: CodexConversionConfig): boolean {
|
|
@@ -32,18 +31,6 @@ export function registerCodexCommand(pi: ExtensionAPI, state: AdapterState, onCo
|
|
|
32
31
|
handler: async (args, ctx) => {
|
|
33
32
|
state.config = readCodexConversionConfig();
|
|
34
33
|
const arg = args.trim().toLowerCase();
|
|
35
|
-
if (arg === "compact") {
|
|
36
|
-
if (!ctx.hasUI) {
|
|
37
|
-
ctx.ui.notify(formatCodexSettings(state.config), "info");
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
await openCodexSettingsScreen(ctx, {
|
|
41
|
-
initialConfig: state.config,
|
|
42
|
-
initialTab: "compaction",
|
|
43
|
-
onChange: (config) => saveAndApply(ctx, config),
|
|
44
|
-
});
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
34
|
const nextConfig = getCommandConfigUpdate(arg, state.config);
|
|
48
35
|
if (nextConfig) {
|
|
49
36
|
saveAndApply(ctx, nextConfig);
|
|
@@ -51,7 +38,7 @@ export function registerCodexCommand(pi: ExtensionAPI, state: AdapterState, onCo
|
|
|
51
38
|
}
|
|
52
39
|
|
|
53
40
|
if (arg) {
|
|
54
|
-
ctx.ui.notify(
|
|
41
|
+
ctx.ui.notify("Usage: /codex, /codex all, /codex status, /codex fast, /codex search, /codex image, /codex low|medium|high", "warning");
|
|
55
42
|
return;
|
|
56
43
|
}
|
|
57
44
|
|
|
@@ -79,5 +66,5 @@ function getCommandConfigUpdate(arg: string, config: CodexConversionConfig): Cod
|
|
|
79
66
|
}
|
|
80
67
|
|
|
81
68
|
function formatCodexSettings(config: CodexConversionConfig): string {
|
|
82
|
-
return `Codex settings: all models ${config.useOnAllModels ? "on" : "off"}, statusline ${config.statusLine ? "on" : "off"}, fast ${config.fast ? "on" : "off"}, web search ${config.webSearch ? "on" : "off"}, image generation ${config.imageGeneration ? "on" : "off"},
|
|
69
|
+
return `Codex settings: all models ${config.useOnAllModels ? "on" : "off"}, statusline ${config.statusLine ? "on" : "off"}, fast ${config.fast ? "on" : "off"}, web search ${config.webSearch ? "on" : "off"}, image generation ${config.imageGeneration ? "on" : "off"}, verbosity ${config.verbosity}`;
|
|
83
70
|
}
|
package/src/codex-settings/ui.ts
CHANGED
|
@@ -1,64 +1,67 @@
|
|
|
1
|
-
import { getSettingsListTheme, type ExtensionContext
|
|
2
|
-
import { SettingsList,
|
|
3
|
-
import {
|
|
4
|
-
COMPACTION_MODELS,
|
|
5
|
-
COMPACTION_REASONING_LEVELS,
|
|
6
|
-
DEFAULT_CODEX_CONVERSION_CONFIG,
|
|
7
|
-
normalizeCodexVerbosity,
|
|
8
|
-
normalizeCompactionModel,
|
|
9
|
-
normalizeCompactionReasoning,
|
|
10
|
-
type CodexConversionConfig,
|
|
11
|
-
} from "../adapter/config.ts";
|
|
1
|
+
import { DynamicBorder, getSettingsListTheme, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Box, Container, SettingsList, Spacer, Text, type SettingItem } from "@earendil-works/pi-tui";
|
|
3
|
+
import { DEFAULT_CODEX_CONVERSION_CONFIG, normalizeCodexVerbosity, type CodexConversionConfig } from "../adapter/config.ts";
|
|
12
4
|
import { CHANGELOG_URL, DISCORD_URL, GITHUB_URL, ISSUE_URL, openExternalUrl } from "./links.ts";
|
|
13
5
|
|
|
14
6
|
export interface CodexSettingsScreenOptions {
|
|
15
7
|
initialConfig: CodexConversionConfig;
|
|
16
8
|
onChange: (nextConfig: CodexConversionConfig) => boolean;
|
|
17
|
-
initialTab?: SettingsTab;
|
|
18
9
|
}
|
|
19
10
|
|
|
20
|
-
type SettingsTab = "general" | "compaction";
|
|
21
|
-
|
|
22
|
-
const TAB_ORDER: readonly SettingsTab[] = ["general", "compaction"];
|
|
23
|
-
|
|
24
11
|
export async function openCodexSettingsScreen(ctx: ExtensionContext, options: CodexSettingsScreenOptions): Promise<void> {
|
|
25
12
|
let draft = { ...options.initialConfig };
|
|
26
|
-
let activeTab: SettingsTab = options.initialTab ?? "general";
|
|
27
|
-
|
|
28
13
|
await ctx.ui.custom<void>((tui, theme, _kb, done) => {
|
|
29
|
-
|
|
30
|
-
draft
|
|
31
|
-
|
|
14
|
+
const buildItems = (): SettingItem[] => [
|
|
15
|
+
{ id: "useOnAllModels", label: "Use on all models", currentValue: draft.useOnAllModels ? "on" : "off", values: ["off", "on"] },
|
|
16
|
+
{ id: "statusLine", label: "Statusline", currentValue: draft.statusLine ? "on" : "off", values: ["off", "on"] },
|
|
17
|
+
{ id: "fast", label: "Fast mode", currentValue: draft.fast ? "on" : "off", values: ["off", "on"] },
|
|
18
|
+
{ id: "webSearch", label: "Web search", currentValue: draft.webSearch ? "on" : "off", values: ["off", "on"] },
|
|
19
|
+
{ id: "imageGeneration", label: "Image generation", currentValue: draft.imageGeneration ? "on" : "off", values: ["off", "on"] },
|
|
20
|
+
{ id: "verbosity", label: "Verbosity", currentValue: draft.verbosity, values: ["low", "medium", "high"] },
|
|
21
|
+
];
|
|
32
22
|
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
23
|
+
const container = new Container();
|
|
24
|
+
const panel = new Box(1, 0);
|
|
25
|
+
panel.addChild(new DynamicBorder((text) => theme.fg("accent", text)));
|
|
26
|
+
let settingsList: SettingsList;
|
|
27
|
+
settingsList = new SettingsList(buildItems(), 6, getSettingsListTheme(), (id, value) => {
|
|
28
|
+
const nextDraft = { ...draft };
|
|
29
|
+
const previousValue = buildItems().find((item) => item.id === id)?.currentValue;
|
|
30
|
+
if (id === "useOnAllModels") nextDraft.useOnAllModels = value === "on";
|
|
31
|
+
if (id === "statusLine") nextDraft.statusLine = value === "on";
|
|
32
|
+
if (id === "fast") nextDraft.fast = value === "on";
|
|
33
|
+
if (id === "webSearch") nextDraft.webSearch = value === "on";
|
|
34
|
+
if (id === "imageGeneration") nextDraft.imageGeneration = value === "on";
|
|
35
|
+
if (id === "verbosity") nextDraft.verbosity = normalizeCodexVerbosity(value) ?? DEFAULT_CODEX_CONVERSION_CONFIG.verbosity;
|
|
36
|
+
if (options.onChange(nextDraft)) {
|
|
37
37
|
draft = nextDraft;
|
|
38
|
-
}
|
|
38
|
+
} else if (previousValue !== undefined) {
|
|
39
|
+
settingsList.updateValue(id, previousValue);
|
|
40
|
+
}
|
|
39
41
|
tui.requestRender();
|
|
40
|
-
};
|
|
42
|
+
}, () => done(undefined));
|
|
43
|
+
panel.addChild(settingsList);
|
|
44
|
+
panel.addChild(new DynamicBorder((text) => theme.fg("dim", text)));
|
|
45
|
+
panel.addChild(
|
|
46
|
+
new Text(
|
|
47
|
+
[
|
|
48
|
+
`${theme.bold("g")} github ${theme.fg("dim", GITHUB_URL)}`,
|
|
49
|
+
`${theme.bold("c")} changes ${theme.fg("dim", CHANGELOG_URL)}`,
|
|
50
|
+
`${theme.bold("d")} discord ${theme.fg("dim", DISCORD_URL)}`,
|
|
51
|
+
`${theme.bold("i")} issue ${theme.fg("dim", ISSUE_URL)}`,
|
|
52
|
+
].join("\n"),
|
|
53
|
+
0,
|
|
54
|
+
0,
|
|
55
|
+
),
|
|
56
|
+
);
|
|
57
|
+
panel.addChild(new DynamicBorder((text) => theme.fg("accent", text)));
|
|
58
|
+
container.addChild(new Spacer(1));
|
|
59
|
+
container.addChild(panel);
|
|
41
60
|
|
|
42
61
|
return {
|
|
43
|
-
render: (width: number) =>
|
|
44
|
-
|
|
45
|
-
rule(width, theme, "accent"),
|
|
46
|
-
formatTabs(activeTab, theme),
|
|
47
|
-
rule(width, theme, "borderMuted"),
|
|
48
|
-
...(activeTab === "compaction" ? formatCompactionNotes(theme) : []),
|
|
49
|
-
"",
|
|
50
|
-
...settingsList.render(width),
|
|
51
|
-
rule(width, theme, "borderMuted"),
|
|
52
|
-
...formatLinks(theme),
|
|
53
|
-
rule(width, theme, "accent"),
|
|
54
|
-
theme.fg("dim", " Tab to switch sections · g/c/d/i open links"),
|
|
55
|
-
].map((line) => truncateToWidth(line, width, "")),
|
|
56
|
-
invalidate: () => settingsList.invalidate(),
|
|
62
|
+
render: (width: number) => container.render(width),
|
|
63
|
+
invalidate: () => container.invalidate(),
|
|
57
64
|
handleInput: (data: string) => {
|
|
58
|
-
if (data === "\t") {
|
|
59
|
-
switchTab();
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
65
|
if (handleLinkKey(data, ctx)) return;
|
|
63
66
|
settingsList.handleInput?.(data);
|
|
64
67
|
tui.requestRender();
|
|
@@ -67,87 +70,6 @@ export async function openCodexSettingsScreen(ctx: ExtensionContext, options: Co
|
|
|
67
70
|
});
|
|
68
71
|
}
|
|
69
72
|
|
|
70
|
-
function formatCompactionNotes(theme: Theme): string[] {
|
|
71
|
-
return [
|
|
72
|
-
theme.fg("dim", " Beta: native OpenAI Responses compaction is experimental. Please report any issues."),
|
|
73
|
-
theme.fg("error", " Warning: do not turn this off mid-session; old context may be much less reliable."),
|
|
74
|
-
];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function rule(width: number, theme: Theme, color: "accent" | "borderMuted"): string {
|
|
78
|
-
return theme.fg(color, "─".repeat(Math.max(0, width)));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function createSettingsList(
|
|
82
|
-
tab: SettingsTab,
|
|
83
|
-
draft: CodexConversionConfig,
|
|
84
|
-
options: CodexSettingsScreenOptions,
|
|
85
|
-
onDraftChanged: (draft: CodexConversionConfig) => void,
|
|
86
|
-
done: (value?: void) => void,
|
|
87
|
-
requestRender: () => void,
|
|
88
|
-
): SettingsList {
|
|
89
|
-
let settingsList: SettingsList;
|
|
90
|
-
settingsList = new SettingsList(buildItems(tab, draft), 8, getSettingsListTheme(), (id, value) => {
|
|
91
|
-
const nextDraft = applySettingChange(id, value, draft);
|
|
92
|
-
const previousValue = buildItems(tab, draft).find((item) => item.id === id)?.currentValue;
|
|
93
|
-
if (options.onChange(nextDraft)) {
|
|
94
|
-
onDraftChanged(nextDraft);
|
|
95
|
-
draft = nextDraft;
|
|
96
|
-
} else if (previousValue !== undefined) {
|
|
97
|
-
settingsList.updateValue(id, previousValue);
|
|
98
|
-
}
|
|
99
|
-
requestRender();
|
|
100
|
-
}, () => done(undefined));
|
|
101
|
-
return settingsList;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function buildItems(tab: SettingsTab, draft: CodexConversionConfig): SettingItem[] {
|
|
105
|
-
if (tab === "compaction") {
|
|
106
|
-
return [
|
|
107
|
-
{ id: "responsesCompaction", label: "Responses compaction", currentValue: (draft.responsesCompaction ?? false) ? "on" : "off", values: ["off", "on"] },
|
|
108
|
-
{ id: "compactionModel", label: "Model", currentValue: draft.compactionModel, values: [...COMPACTION_MODELS] },
|
|
109
|
-
{ id: "compactionReasoning", label: "Reasoning", currentValue: draft.compactionReasoning, values: [...COMPACTION_REASONING_LEVELS] },
|
|
110
|
-
];
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return [
|
|
114
|
-
{ id: "useOnAllModels", label: "Use on all models", currentValue: draft.useOnAllModels ? "on" : "off", values: ["off", "on"] },
|
|
115
|
-
{ id: "statusLine", label: "Statusline", currentValue: draft.statusLine ? "on" : "off", values: ["off", "on"] },
|
|
116
|
-
{ id: "fast", label: "Fast mode", currentValue: draft.fast ? "on" : "off", values: ["off", "on"] },
|
|
117
|
-
{ id: "webSearch", label: "Web search", currentValue: draft.webSearch ? "on" : "off", values: ["off", "on"] },
|
|
118
|
-
{ id: "imageGeneration", label: "Image generation", currentValue: draft.imageGeneration ? "on" : "off", values: ["off", "on"] },
|
|
119
|
-
{ id: "verbosity", label: "Verbosity", currentValue: draft.verbosity, values: ["low", "medium", "high"] },
|
|
120
|
-
];
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function applySettingChange(id: string, value: string, draft: CodexConversionConfig): CodexConversionConfig {
|
|
124
|
-
const nextDraft = { ...draft };
|
|
125
|
-
if (id === "useOnAllModels") nextDraft.useOnAllModels = value === "on";
|
|
126
|
-
if (id === "statusLine") nextDraft.statusLine = value === "on";
|
|
127
|
-
if (id === "fast") nextDraft.fast = value === "on";
|
|
128
|
-
if (id === "webSearch") nextDraft.webSearch = value === "on";
|
|
129
|
-
if (id === "imageGeneration") nextDraft.imageGeneration = value === "on";
|
|
130
|
-
if (id === "responsesCompaction") nextDraft.responsesCompaction = value === "on";
|
|
131
|
-
if (id === "compactionModel") nextDraft.compactionModel = normalizeCompactionModel(value) ?? DEFAULT_CODEX_CONVERSION_CONFIG.compactionModel;
|
|
132
|
-
if (id === "compactionReasoning") nextDraft.compactionReasoning = normalizeCompactionReasoning(value) ?? DEFAULT_CODEX_CONVERSION_CONFIG.compactionReasoning;
|
|
133
|
-
if (id === "verbosity") nextDraft.verbosity = normalizeCodexVerbosity(value) ?? DEFAULT_CODEX_CONVERSION_CONFIG.verbosity;
|
|
134
|
-
return nextDraft;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function formatTabs(activeTab: SettingsTab, theme: Theme): string {
|
|
138
|
-
const renderTab = (tab: SettingsTab, label: string) => activeTab === tab ? theme.bold(label) : theme.fg("dim", label);
|
|
139
|
-
return ` ${renderTab("general", "General")} ${theme.fg("dim", "/")} ${renderTab("compaction", "Compaction")}`;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function formatLinks(theme: Theme): string[] {
|
|
143
|
-
return [
|
|
144
|
-
`${theme.bold("g")} github ${theme.fg("dim", GITHUB_URL)}`,
|
|
145
|
-
`${theme.bold("c")} changes ${theme.fg("dim", CHANGELOG_URL)}`,
|
|
146
|
-
`${theme.bold("d")} discord ${theme.fg("dim", DISCORD_URL)}`,
|
|
147
|
-
`${theme.bold("i")} issue ${theme.fg("dim", ISSUE_URL)}`,
|
|
148
|
-
];
|
|
149
|
-
}
|
|
150
|
-
|
|
151
73
|
function handleLinkKey(data: string, ctx: ExtensionContext): boolean {
|
|
152
74
|
const target = getLinkTarget(data);
|
|
153
75
|
if (!target) return false;
|
package/src/index.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { Box, Text, truncateToWidth } from "@earendil-works/pi-tui";
|
|
3
2
|
import { getCodexRuntimeShell } from "./adapter/runtime-shell.ts";
|
|
4
3
|
import { clearApplyPatchRenderState, registerApplyPatchTool } from "./tools/apply-patch-tool.ts";
|
|
5
4
|
import { createExecCommandTracker } from "./tools/exec-command-state.ts";
|
|
6
5
|
import { registerExecCommandTool } from "./tools/exec-command-tool.ts";
|
|
7
6
|
import { createExecSessionManager } from "./tools/exec-session-manager.ts";
|
|
8
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
IMAGE_SAVE_DISPLAY_MESSAGE_TYPE,
|
|
9
|
+
WEB_SEARCH_ACTIVITY_MESSAGE_TYPE,
|
|
10
|
+
registerOpenAICodexCustomProvider,
|
|
11
|
+
} from "./providers/openai-codex-custom-provider.ts";
|
|
9
12
|
import { registerImageGenerationTool } from "./tools/image-generation-tool.ts";
|
|
10
13
|
import { buildCodexSystemPrompt, extractPiPromptSkills, resolvePromptSkills } from "./prompt/build-system-prompt.ts";
|
|
11
14
|
import { registerViewImageTool, supportsOriginalImageDetail } from "./tools/view-image-tool.ts";
|
|
12
|
-
import { registerWebSearchTool } from "./tools/web-search-tool.ts";
|
|
15
|
+
import { registerWebSearchTool, WEB_SEARCH_SESSION_NOTE_TYPE } from "./tools/web-search-tool.ts";
|
|
13
16
|
import { registerWriteStdinTool } from "./tools/write-stdin-tool.ts";
|
|
14
17
|
import { ensureBundledApplyPatchOnPath } from "./tools/apply-patch-binary.ts";
|
|
15
18
|
import { readCodexConversionConfig } from "./adapter/config.ts";
|
|
16
19
|
import { syncAdapter, mergeAdapterTools, restoreTools, stripAdapterTools, shouldUseCodexAdapter } from "./adapter/activation.ts";
|
|
17
20
|
import { rewriteCodexProviderRequest } from "./adapter/provider-request.ts";
|
|
18
|
-
import { handleCodexSessionBeforeCompact } from "./adapter/compaction.ts";
|
|
19
|
-
import { isNativeCompactionDetails, NATIVE_COMPACTION_DISPLAY_MESSAGE_TYPE, NATIVE_COMPACTION_DISPLAY_TEXT } from "./adapter/types.ts";
|
|
20
|
-
import { isAdapterContextExcludedCustomMessage } from "./adapter/context-filter.ts";
|
|
21
21
|
import { getCodexSkillPaths } from "./adapter/skills.ts";
|
|
22
22
|
import type { AdapterState } from "./adapter/state.ts";
|
|
23
23
|
import { registerCodexCommand } from "./codex-settings/command.ts";
|
|
@@ -67,16 +67,6 @@ export default function codexConversion(pi: ExtensionAPI) {
|
|
|
67
67
|
ensureOptionalNativeToolsRegistered();
|
|
68
68
|
registerCodexCommand(pi, state, ensureOptionalNativeToolsRegistered);
|
|
69
69
|
|
|
70
|
-
pi.registerMessageRenderer(NATIVE_COMPACTION_DISPLAY_MESSAGE_TYPE, (message, _options, theme) => {
|
|
71
|
-
const box = new Box(1, 1, (text) => theme.bg("customMessageBg", text));
|
|
72
|
-
box.addChild(new Text(theme.fg("customMessageLabel", theme.bold("[compaction]")), 0, 0));
|
|
73
|
-
const content = typeof message.content === "string" ? message.content : NATIVE_COMPACTION_DISPLAY_TEXT;
|
|
74
|
-
box.addChild(new Text(`\n${theme.fg("customMessageText", content)}`, 0, 0));
|
|
75
|
-
const render = box.render.bind(box);
|
|
76
|
-
box.render = (width) => render(width).map((line) => truncateToWidth(line, width, ""));
|
|
77
|
-
return box;
|
|
78
|
-
});
|
|
79
|
-
|
|
80
70
|
sessions.onSessionExit((sessionId) => {
|
|
81
71
|
tracker.recordSessionFinished(sessionId);
|
|
82
72
|
});
|
|
@@ -148,25 +138,19 @@ export default function codexConversion(pi: ExtensionAPI) {
|
|
|
148
138
|
return rewriteCodexProviderRequest(event.payload, ctx, state);
|
|
149
139
|
});
|
|
150
140
|
|
|
151
|
-
pi.on("
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
details: { compactionEntryId: event.compactionEntry.id },
|
|
164
|
-
},
|
|
165
|
-
{ triggerTurn: false },
|
|
166
|
-
);
|
|
141
|
+
pi.on("context", async (event) => {
|
|
142
|
+
return {
|
|
143
|
+
messages: event.messages.filter(
|
|
144
|
+
(message) =>
|
|
145
|
+
!(
|
|
146
|
+
message.role === "custom" &&
|
|
147
|
+
(message.customType === WEB_SEARCH_SESSION_NOTE_TYPE ||
|
|
148
|
+
message.customType === WEB_SEARCH_ACTIVITY_MESSAGE_TYPE ||
|
|
149
|
+
message.customType === IMAGE_SAVE_DISPLAY_MESSAGE_TYPE)
|
|
150
|
+
),
|
|
151
|
+
),
|
|
152
|
+
};
|
|
167
153
|
});
|
|
168
|
-
|
|
169
|
-
pi.on("context", async (event) => ({ messages: event.messages.filter((message) => !isAdapterContextExcludedCustomMessage(message)) }));
|
|
170
154
|
}
|
|
171
155
|
|
|
172
156
|
export { getCodexSkillPaths, mergeAdapterTools, restoreTools, stripAdapterTools };
|
|
@@ -17,7 +17,6 @@ import type { ResponseCreateParamsStreaming } from "openai/resources/responses/r
|
|
|
17
17
|
import {
|
|
18
18
|
convertResponsesMessages,
|
|
19
19
|
convertResponsesTools,
|
|
20
|
-
CODEX_TOOL_CALL_PROVIDERS,
|
|
21
20
|
processResponsesStream,
|
|
22
21
|
} from "./openai-responses-shared.ts";
|
|
23
22
|
|
|
@@ -29,6 +28,7 @@ const OPENAI_CODEX_IMAGE_DIR = ".pi/openai-codex-images";
|
|
|
29
28
|
const OPENAI_CODEX_LATEST_IMAGE_NAME = "latest.png";
|
|
30
29
|
const MAX_RETRIES = 3;
|
|
31
30
|
const BASE_DELAY_MS = 1000;
|
|
31
|
+
const CODEX_TOOL_CALL_PROVIDERS = new Set(["openai", "openai-codex", "opencode"]);
|
|
32
32
|
const CODEX_RESPONSE_STATUSES = new Set(["completed", "incomplete", "failed", "cancelled", "queued", "in_progress"]);
|
|
33
33
|
const OPENAI_BETA_RESPONSES_WEBSOCKETS = "responses_websockets=2026-02-06";
|
|
34
34
|
const WEBSOCKET_MESSAGE_TOO_BIG_CLOSE_CODE = 1009;
|
|
@@ -40,8 +40,6 @@ interface ConvertResponsesToolsOptions {
|
|
|
40
40
|
strict?: boolean | null;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
export const CODEX_TOOL_CALL_PROVIDERS = new Set(["openai", "openai-codex", "opencode"]);
|
|
44
|
-
|
|
45
43
|
function shortHash(str: string): string {
|
|
46
44
|
let h1 = 0xdeadbeef;
|
|
47
45
|
let h2 = 0x41c6ce57;
|
|
Binary file
|
|
Binary file
|