@oai404iao/pi-codex-minimal-tools 1.4.0 → 2.0.0
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 +44 -17
- package/THIRD_PARTY_NOTICES.md +20 -0
- package/config.schema.json +1 -2
- package/index.ts +2 -0
- package/package.json +14 -13
- package/provenance/openai-codex-ddea03ad-astra.json +54 -0
- package/src/activation.ts +1 -56
- package/src/adapter/compaction/checkpoint.ts +1 -0
- package/src/adapter/compaction/collect.ts +1 -0
- package/src/adapter/compaction/http.ts +1 -0
- package/src/adapter/compaction/request.ts +1 -0
- package/src/adapter/compaction/transport.ts +1 -0
- package/src/adapter/compaction/websocket.ts +1 -0
- package/src/background-image-generation.ts +1 -574
- package/src/capabilities.ts +1 -146
- package/src/codex-http.ts +1 -133
- package/src/codex-identity-extension.ts +1 -339
- package/src/codex-request-profile.ts +1 -45
- package/src/codex-reserved-tools.ts +1 -323
- package/src/codex-wire-identity.ts +1 -596
- package/src/extension/prewarm-snapshot.ts +1 -0
- package/src/extension/provider-presentation.ts +1 -0
- package/src/extension/provider-runtime.ts +1 -0
- package/src/extension/register.ts +36 -0
- package/src/extension/startup-prewarm.ts +1 -0
- package/src/fast-mode.ts +1 -124
- package/src/glyphs.ts +1 -70
- package/src/index.ts +8 -331
- package/src/model-catalog/catalog.ts +1 -636
- package/src/model-catalog/default-models.json +8 -0
- package/src/model-catalog/runtime.ts +1 -113
- package/src/model-catalog/types.ts +1 -95
- package/src/native-compaction.ts +1 -393
- package/src/patch/apply.ts +1 -338
- package/src/patch/parser.ts +1 -224
- package/src/patch/render.ts +1 -201
- package/src/provider-headers.ts +1 -54
- package/src/provider-native-tools.ts +1 -71
- package/src/provider-shim.ts +20 -4511
- package/src/providers/codex-apply-patch-tool.ts +1 -23
- package/src/providers/openai-codex/cache-key.ts +1 -0
- package/src/providers/openai-codex/captured-stream.ts +1 -0
- package/src/providers/openai-codex/constants.ts +1 -0
- package/src/providers/openai-codex/continuation.ts +1 -0
- package/src/providers/openai-codex/errors.ts +1 -0
- package/src/providers/openai-codex/events.ts +1 -0
- package/src/providers/openai-codex/headers.ts +1 -0
- package/src/providers/openai-codex/lite.ts +1 -0
- package/src/providers/openai-codex/message.ts +1 -0
- package/src/providers/openai-codex/prewarm.ts +1 -0
- package/src/providers/openai-codex/proxy.ts +1 -0
- package/src/providers/openai-codex/reasoning.ts +1 -0
- package/src/providers/openai-codex/request-body.ts +1 -0
- package/src/providers/openai-codex/request-context.ts +1 -0
- package/src/providers/openai-codex/request-metadata.ts +1 -0
- package/src/providers/openai-codex/retry.ts +1 -0
- package/src/providers/openai-codex/runtime.ts +1 -0
- package/src/providers/openai-codex/sse.ts +1 -0
- package/src/providers/openai-codex/stream-effects.ts +1 -0
- package/src/providers/openai-codex/stream.ts +1 -0
- package/src/providers/openai-codex/types.ts +1 -0
- package/src/providers/openai-codex/urls.ts +1 -0
- package/src/providers/openai-codex/usage.ts +1 -0
- package/src/providers/openai-codex/websocket-connection.ts +1 -0
- package/src/providers/openai-codex/websocket-events.ts +1 -0
- package/src/providers/openai-codex/websocket-session.ts +1 -0
- package/src/providers/openai-codex/websocket-socket.ts +1 -0
- package/src/providers/openai-codex/websocket-stream.ts +1 -0
- package/src/providers/openai-responses-shared.ts +7 -1463
- package/src/providers/responses/citations.ts +1 -0
- package/src/providers/responses/history.ts +1 -0
- package/src/providers/responses/items.ts +1 -0
- package/src/providers/responses/markdown.ts +1 -0
- package/src/providers/responses/messages.ts +1 -0
- package/src/providers/responses/signatures.ts +1 -0
- package/src/providers/responses/stream-state.ts +1 -0
- package/src/providers/responses/stream.ts +1 -0
- package/src/providers/responses/text-renderer.ts +1 -0
- package/src/providers/responses/text.ts +1 -0
- package/src/providers/responses/tool-identity.ts +1 -0
- package/src/providers/responses/tools.ts +1 -0
- package/src/providers/responses/types.ts +1 -0
- package/src/providers/responses/usage.ts +1 -0
- package/src/settings.ts +1 -247
- package/src/subagent-inline.ts +1 -8
- package/src/tools/apply-patch.ts +1 -84
- package/src/tools/image-generation/capture.ts +1 -0
- package/src/tools/image-generation/display.ts +1 -0
- package/src/tools/image-generation/preview.ts +1 -0
- package/src/tools/image-generation/storage.ts +1 -0
- package/src/tools/image-generation/types.ts +1 -0
- package/src/tools/image-generation.ts +1 -274
- package/src/tools/view-image.ts +1 -98
- package/src/tools/web-search/activity.ts +1 -0
- package/src/tools/web-search/capture.ts +1 -0
- package/src/tools/web-search/render.ts +1 -0
- package/src/tools/web-search.ts +1 -554
- package/src/utils/images.ts +1 -73
- package/src/utils/theme.ts +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@oai404iao/pi-codex-runtime/internal/providers/responses/citations";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@oai404iao/pi-codex-runtime/internal/providers/responses/history";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@oai404iao/pi-codex-runtime/internal/providers/responses/items";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@oai404iao/pi-codex-runtime/internal/providers/responses/markdown";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@oai404iao/pi-codex-runtime/internal/providers/responses/messages";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@oai404iao/pi-codex-runtime/internal/providers/responses/signatures";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@oai404iao/pi-codex-runtime/internal/providers/responses/stream-state";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@oai404iao/pi-codex-runtime/internal/providers/responses/stream";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@oai404iao/pi-codex-runtime/internal/providers/responses/text-renderer";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@oai404iao/pi-codex-runtime/internal/providers/responses/text";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@oai404iao/pi-codex-runtime/internal/providers/responses/tool-identity";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@oai404iao/pi-codex-runtime/internal/providers/responses/tools";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@oai404iao/pi-codex-runtime/internal/providers/responses/types";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@oai404iao/pi-codex-runtime/internal/providers/responses/usage";
|
package/src/settings.ts
CHANGED
|
@@ -1,247 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
|
-
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
4
|
-
import type { CodexRequestProfileOverride } from "./codex-request-profile.js";
|
|
5
|
-
|
|
6
|
-
export const PACKAGE_NAME = "pi-codex-minimal-tools";
|
|
7
|
-
export const CONFIG_FILE_NAME = "config.json";
|
|
8
|
-
|
|
9
|
-
export interface CodexMinimalToolsSettings {
|
|
10
|
-
enabled: boolean;
|
|
11
|
-
glyphStyle: "unicode" | "ascii";
|
|
12
|
-
autoEnable: boolean;
|
|
13
|
-
nativeProviderTools: boolean;
|
|
14
|
-
openaiTransport: "sse" | "websocket" | "websocket-cached" | "auto";
|
|
15
|
-
openaiWebSocketPrewarm: boolean;
|
|
16
|
-
fastMode: boolean;
|
|
17
|
-
compactionMode: "pi" | "responses" | "responses-compact";
|
|
18
|
-
requestProfile: CodexRequestProfileOverride;
|
|
19
|
-
apiKeyMode: boolean;
|
|
20
|
-
imageGeneration: boolean;
|
|
21
|
-
webSearchEnabled: boolean;
|
|
22
|
-
imageOutputDir: string;
|
|
23
|
-
imageModel: "gpt-image-2" | "gpt-image-1.5" | "gpt-image-1";
|
|
24
|
-
directImageApiFallback: boolean;
|
|
25
|
-
viewImage: boolean;
|
|
26
|
-
viewImageWorkspaceOnly: boolean;
|
|
27
|
-
applyPatchEnabled: boolean;
|
|
28
|
-
additionalModelIds: string[];
|
|
29
|
-
deferApplyPatchRendering: boolean;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const DEFAULT_SETTINGS: CodexMinimalToolsSettings = {
|
|
33
|
-
enabled: true,
|
|
34
|
-
glyphStyle: "unicode",
|
|
35
|
-
autoEnable: true,
|
|
36
|
-
nativeProviderTools: true,
|
|
37
|
-
openaiTransport: "sse",
|
|
38
|
-
openaiWebSocketPrewarm: true,
|
|
39
|
-
fastMode: false,
|
|
40
|
-
compactionMode: "pi",
|
|
41
|
-
requestProfile: {},
|
|
42
|
-
apiKeyMode: false,
|
|
43
|
-
imageGeneration: true,
|
|
44
|
-
webSearchEnabled: false,
|
|
45
|
-
imageOutputDir: ".pi/openai-codex-images",
|
|
46
|
-
imageModel: "gpt-image-2",
|
|
47
|
-
directImageApiFallback: false,
|
|
48
|
-
viewImage: false,
|
|
49
|
-
viewImageWorkspaceOnly: false,
|
|
50
|
-
applyPatchEnabled: true,
|
|
51
|
-
additionalModelIds: [],
|
|
52
|
-
deferApplyPatchRendering: false,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
type SettingsRecord = Record<string, unknown>;
|
|
56
|
-
const settingsParseWarnings = new Map<string, string>();
|
|
57
|
-
const SETTINGS_SOURCE = Symbol("pi-codex-minimal-tools.settings-source");
|
|
58
|
-
|
|
59
|
-
function expandHome(input: string): string {
|
|
60
|
-
if (input === "~") return homedir();
|
|
61
|
-
if (input.startsWith("~/")) return join(homedir(), input.slice(2));
|
|
62
|
-
return input;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function piUserDir(): string {
|
|
66
|
-
const envDir = process.env.PI_CODING_AGENT_DIR?.trim();
|
|
67
|
-
if (envDir) return resolve(expandHome(envDir));
|
|
68
|
-
|
|
69
|
-
const xdgConfigHome = process.env.XDG_CONFIG_HOME?.trim();
|
|
70
|
-
const xdgAgentDir = xdgConfigHome
|
|
71
|
-
? resolve(expandHome(xdgConfigHome), "pi", "agent")
|
|
72
|
-
: join(homedir(), ".config", "pi", "agent");
|
|
73
|
-
if (existsSync(xdgAgentDir)) return xdgAgentDir;
|
|
74
|
-
|
|
75
|
-
return resolve(expandHome("~/.pi/agent"));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function configDir(agentDir = piUserDir()): string {
|
|
79
|
-
return join(agentDir, "extensions", PACKAGE_NAME);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function configPath(agentDir = piUserDir()): string {
|
|
83
|
-
return join(configDir(agentDir), CONFIG_FILE_NAME);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function asRecord(value: unknown): SettingsRecord | undefined {
|
|
87
|
-
return value && typeof value === "object" && !Array.isArray(value) ? (value as SettingsRecord) : undefined;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function readRawConfig(): SettingsRecord {
|
|
91
|
-
const path = configPath();
|
|
92
|
-
if (!existsSync(path)) return {};
|
|
93
|
-
try {
|
|
94
|
-
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
95
|
-
settingsParseWarnings.delete(path);
|
|
96
|
-
return asRecord(parsed) ?? {};
|
|
97
|
-
} catch (error) {
|
|
98
|
-
settingsParseWarnings.set(path, error instanceof Error ? error.message : String(error));
|
|
99
|
-
return {};
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export function settingsDiagnostics(): string[] {
|
|
104
|
-
readRawConfig();
|
|
105
|
-
const path = configPath();
|
|
106
|
-
const warning = settingsParseWarnings.get(path);
|
|
107
|
-
return warning ? [`${path}: ${warning}`] : [];
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function boolSetting(raw: SettingsRecord, key: keyof CodexMinimalToolsSettings): boolean {
|
|
111
|
-
const fallback = DEFAULT_SETTINGS[key];
|
|
112
|
-
const value = raw[key as string];
|
|
113
|
-
return typeof value === "boolean" ? value : Boolean(fallback);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function stringSetting(raw: SettingsRecord, key: keyof CodexMinimalToolsSettings): string {
|
|
117
|
-
const fallback = String(DEFAULT_SETTINGS[key]);
|
|
118
|
-
const value = raw[key as string];
|
|
119
|
-
return typeof value === "string" && value.trim().length > 0 ? value.trim() : fallback;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function modelIdListSetting(raw: SettingsRecord): string[] {
|
|
123
|
-
const value = raw.additionalModelIds;
|
|
124
|
-
if (!Array.isArray(value)) return [...DEFAULT_SETTINGS.additionalModelIds];
|
|
125
|
-
|
|
126
|
-
const seen = new Set<string>();
|
|
127
|
-
const modelIds: string[] = [];
|
|
128
|
-
for (const item of value) {
|
|
129
|
-
if (typeof item !== "string") continue;
|
|
130
|
-
const modelId = item.trim();
|
|
131
|
-
if (!modelId.includes("/")) continue;
|
|
132
|
-
const normalized = modelId.toLowerCase();
|
|
133
|
-
if (seen.has(normalized)) continue;
|
|
134
|
-
seen.add(normalized);
|
|
135
|
-
modelIds.push(modelId);
|
|
136
|
-
}
|
|
137
|
-
return modelIds;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function imageModelSetting(raw: SettingsRecord): CodexMinimalToolsSettings["imageModel"] {
|
|
141
|
-
const value = raw.imageModel;
|
|
142
|
-
return value === "gpt-image-2" || value === "gpt-image-1.5" || value === "gpt-image-1" ? value : DEFAULT_SETTINGS.imageModel;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function glyphStyleSetting(raw: SettingsRecord): CodexMinimalToolsSettings["glyphStyle"] {
|
|
146
|
-
const value = raw.glyphStyle;
|
|
147
|
-
return value === "ascii" || value === "unicode" ? value : DEFAULT_SETTINGS.glyphStyle;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function openaiTransportSetting(raw: SettingsRecord): CodexMinimalToolsSettings["openaiTransport"] {
|
|
151
|
-
const value = raw.openaiTransport;
|
|
152
|
-
return value === "sse" || value === "websocket" || value === "websocket-cached" || value === "auto"
|
|
153
|
-
? value
|
|
154
|
-
: DEFAULT_SETTINGS.openaiTransport;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function compactionModeSetting(raw: SettingsRecord): CodexMinimalToolsSettings["compactionMode"] {
|
|
158
|
-
const value = raw.compactionMode;
|
|
159
|
-
if (value === "responses-context-management") return "responses";
|
|
160
|
-
return value === "pi" || value === "responses" || value === "responses-compact"
|
|
161
|
-
? value
|
|
162
|
-
: DEFAULT_SETTINGS.compactionMode;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function requestProfileSetting(raw: SettingsRecord): CodexRequestProfileOverride {
|
|
166
|
-
const value = asRecord(raw.requestProfile);
|
|
167
|
-
if (!value) return {};
|
|
168
|
-
const profile: CodexRequestProfileOverride = {};
|
|
169
|
-
if (value.responsesMode === "standard" || value.responsesMode === "lite") profile.responsesMode = value.responsesMode;
|
|
170
|
-
if (
|
|
171
|
-
value.reasoningSummary === "auto"
|
|
172
|
-
|| value.reasoningSummary === "concise"
|
|
173
|
-
|| value.reasoningSummary === "detailed"
|
|
174
|
-
|| value.reasoningSummary === "none"
|
|
175
|
-
) {
|
|
176
|
-
profile.reasoningSummary = value.reasoningSummary;
|
|
177
|
-
}
|
|
178
|
-
if (value.systemPromptPlacement === "instructions" || value.systemPromptPlacement === "developer") profile.systemPromptPlacement = value.systemPromptPlacement;
|
|
179
|
-
if (value.patchTransport === "function" || value.patchTransport === "custom") profile.patchTransport = value.patchTransport;
|
|
180
|
-
if (typeof value.supportsHostedTools === "boolean") profile.supportsHostedTools = value.supportsHostedTools;
|
|
181
|
-
if (typeof value.supportsParallelTools === "boolean") profile.supportsParallelTools = value.supportsParallelTools;
|
|
182
|
-
return profile;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export function loadSettings(_cwd?: string): CodexMinimalToolsSettings {
|
|
186
|
-
const raw = readRawConfig();
|
|
187
|
-
const settings: CodexMinimalToolsSettings = {
|
|
188
|
-
enabled: boolSetting(raw, "enabled"),
|
|
189
|
-
glyphStyle: glyphStyleSetting(raw),
|
|
190
|
-
autoEnable: boolSetting(raw, "autoEnable"),
|
|
191
|
-
nativeProviderTools: boolSetting(raw, "nativeProviderTools"),
|
|
192
|
-
openaiTransport: openaiTransportSetting(raw),
|
|
193
|
-
openaiWebSocketPrewarm: boolSetting(raw, "openaiWebSocketPrewarm"),
|
|
194
|
-
fastMode: boolSetting(raw, "fastMode"),
|
|
195
|
-
compactionMode: compactionModeSetting(raw),
|
|
196
|
-
requestProfile: requestProfileSetting(raw),
|
|
197
|
-
apiKeyMode: boolSetting(raw, "apiKeyMode"),
|
|
198
|
-
imageGeneration: boolSetting(raw, "imageGeneration"),
|
|
199
|
-
webSearchEnabled: boolSetting(raw, "webSearchEnabled"),
|
|
200
|
-
imageOutputDir: stringSetting(raw, "imageOutputDir"),
|
|
201
|
-
imageModel: imageModelSetting(raw),
|
|
202
|
-
directImageApiFallback: boolSetting(raw, "directImageApiFallback"),
|
|
203
|
-
viewImage: boolSetting(raw, "viewImage"),
|
|
204
|
-
viewImageWorkspaceOnly: boolSetting(raw, "viewImageWorkspaceOnly"),
|
|
205
|
-
applyPatchEnabled: boolSetting(raw, "applyPatchEnabled"),
|
|
206
|
-
additionalModelIds: modelIdListSetting(raw),
|
|
207
|
-
deferApplyPatchRendering: boolSetting(raw, "deferApplyPatchRendering"),
|
|
208
|
-
};
|
|
209
|
-
Object.defineProperty(settings, SETTINGS_SOURCE, {
|
|
210
|
-
value: raw,
|
|
211
|
-
enumerable: false,
|
|
212
|
-
configurable: false,
|
|
213
|
-
writable: false,
|
|
214
|
-
});
|
|
215
|
-
return settings;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
export function getSettingsSource(settings: CodexMinimalToolsSettings): SettingsRecord | undefined {
|
|
219
|
-
return (settings as CodexMinimalToolsSettings & { [SETTINGS_SOURCE]?: SettingsRecord })[SETTINGS_SOURCE];
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
export function updateConfig(patch: Partial<CodexMinimalToolsSettings>): string {
|
|
223
|
-
const path = configPath();
|
|
224
|
-
let raw: SettingsRecord = {};
|
|
225
|
-
if (existsSync(path)) {
|
|
226
|
-
let parsed: unknown;
|
|
227
|
-
try {
|
|
228
|
-
parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
229
|
-
} catch (error) {
|
|
230
|
-
throw new Error(`Cannot update malformed config ${path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
231
|
-
}
|
|
232
|
-
const record = asRecord(parsed);
|
|
233
|
-
if (!record) throw new Error(`Cannot update config ${path}: root value must be a JSON object`);
|
|
234
|
-
raw = record;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
const next = { ...raw, ...patch };
|
|
238
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
239
|
-
writeFileSync(path, `${JSON.stringify(next, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
240
|
-
settingsParseWarnings.delete(path);
|
|
241
|
-
return path;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
export function resolveSettingsRelativePath(value: string, settingsPath = configPath()): string {
|
|
245
|
-
const expanded = expandHome(value.trim());
|
|
246
|
-
return isAbsolute(expanded) ? expanded : resolve(dirname(settingsPath), expanded);
|
|
247
|
-
}
|
|
1
|
+
export * from "@oai404iao/pi-codex-runtime/internal/settings";
|
package/src/subagent-inline.ts
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
CODEX_IDENTITY_CUSTOM_TYPE,
|
|
3
|
-
createCodexSubagentInlineExtension,
|
|
4
|
-
} from "./codex-identity-extension.js";
|
|
5
|
-
export type {
|
|
6
|
-
CodexIdentitySessionView,
|
|
7
|
-
} from "./codex-identity-extension.js";
|
|
8
|
-
export type { CodexThreadIdentity } from "./codex-wire-identity.js";
|
|
1
|
+
export * from "@oai404iao/pi-codex-runtime/subagent-inline";
|
package/src/tools/apply-patch.ts
CHANGED
|
@@ -1,84 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { parseApplyPatch } from "../patch/parser.js";
|
|
3
|
-
import { createApplyPatchRenderers } from "../patch/render.js";
|
|
4
|
-
|
|
5
|
-
export interface ApplyPatchInput {
|
|
6
|
-
input: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const applyPatchToolSchema = {
|
|
10
|
-
type: "object",
|
|
11
|
-
additionalProperties: false,
|
|
12
|
-
properties: {
|
|
13
|
-
input: { type: "string", description: "Raw Codex patch text. File paths may be relative or absolute. Add File content lines start with +; Update File chunks use context, +, and - lines." },
|
|
14
|
-
},
|
|
15
|
-
required: ["input"],
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export function applyPatchTargetPaths(input: string, cwd: string): string[] {
|
|
19
|
-
const parsed = parseApplyPatch(input);
|
|
20
|
-
const paths = new Set<string>();
|
|
21
|
-
for (const action of parsed.actions) {
|
|
22
|
-
paths.add(resolvePatchPath(action.path, { cwd }));
|
|
23
|
-
if (action.kind === "update" && action.moveTo) paths.add(resolvePatchPath(action.moveTo, { cwd }));
|
|
24
|
-
}
|
|
25
|
-
return [...paths].sort();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async function withMutationQueue(path: string, fn: () => Promise<void>): Promise<void> {
|
|
29
|
-
try {
|
|
30
|
-
const mod = await import("@earendil-works/pi-coding-agent");
|
|
31
|
-
const queue = (mod as { withFileMutationQueue?: (path: string, fn: () => Promise<void>) => Promise<void> }).withFileMutationQueue;
|
|
32
|
-
if (typeof queue === "function") return queue(path, fn);
|
|
33
|
-
} catch {
|
|
34
|
-
// Unit tests can run outside Pi without peer dependencies installed.
|
|
35
|
-
}
|
|
36
|
-
return fn();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export async function executeApplyPatchTool(params: ApplyPatchInput, cwd: string): Promise<{ content: Array<{ type: "text"; text: string }>; details: ApplyPatchResult }> {
|
|
40
|
-
if (!params || typeof params.input !== "string") throw new Error("apply_patch requires an input string.");
|
|
41
|
-
let targets: string[];
|
|
42
|
-
try {
|
|
43
|
-
targets = applyPatchTargetPaths(params.input, cwd);
|
|
44
|
-
} catch (error) {
|
|
45
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
46
|
-
throw new Error(`apply_patch verification failed: ${message}`);
|
|
47
|
-
}
|
|
48
|
-
let result: ApplyPatchResult | undefined;
|
|
49
|
-
const runAt = async (index: number): Promise<void> => {
|
|
50
|
-
if (index >= targets.length) {
|
|
51
|
-
result = await applyPatch(params.input, { cwd });
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
await withMutationQueue(targets[index]!, () => runAt(index + 1));
|
|
55
|
-
};
|
|
56
|
-
await runAt(0);
|
|
57
|
-
if (!result) throw new Error("apply_patch did not produce a result.");
|
|
58
|
-
return {
|
|
59
|
-
content: [{ type: "text", text: result.summary }],
|
|
60
|
-
details: result,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function createApplyPatchToolDefinition(options: { cwd?: string; deferRendering?: boolean } = {}) {
|
|
65
|
-
const definition: Record<string, unknown> = {
|
|
66
|
-
renderShell: "self",
|
|
67
|
-
name: "apply_patch",
|
|
68
|
-
label: "Apply Patch",
|
|
69
|
-
description: "Use apply_patch to edit files with the Codex patch format. A patch starts with *** Begin Patch, contains one or more Add, Update, or Delete file sections, and ends with *** End Patch.",
|
|
70
|
-
promptSnippet: "Apply Codex-style multi-file patches with contextual update hunks and explicit Add, Update, or Delete headers.",
|
|
71
|
-
promptGuidelines: [
|
|
72
|
-
"Use apply_patch for concise multi-file edits when a Codex-style patch is clearer than separate edit/write calls.",
|
|
73
|
-
"In apply_patch, paths may be relative to the current working directory or absolute; prefix every Add File content line with +; and use @@ class/function context plus surrounding lines when repeated code needs disambiguation.",
|
|
74
|
-
"Use *** End of File in apply_patch when a hunk must match the end of a file.",
|
|
75
|
-
],
|
|
76
|
-
parameters: applyPatchToolSchema,
|
|
77
|
-
async execute(_toolCallId: string, params: ApplyPatchInput, _signal: AbortSignal | undefined, _onUpdate: unknown, ctx: { cwd: string }) {
|
|
78
|
-
const cwd = ctx?.cwd ?? options.cwd ?? process.cwd();
|
|
79
|
-
return executeApplyPatchTool(params, cwd);
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
if (!options.deferRendering) Object.assign(definition, createApplyPatchRenderers());
|
|
83
|
-
return definition;
|
|
84
|
-
}
|
|
1
|
+
export * from "@oai404iao/pi-codex-core/internal/tools/apply-patch";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@oai404iao/pi-codex-imagegen/internal/tools/image-generation/capture";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@oai404iao/pi-codex-imagegen/internal/tools/image-generation/display";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@oai404iao/pi-codex-imagegen/internal/tools/image-generation/preview";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@oai404iao/pi-codex-imagegen/internal/tools/image-generation/storage";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@oai404iao/pi-codex-imagegen/internal/tools/image-generation/types";
|