@hexdecimal16/nexo 0.4.9 → 0.4.11
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/core/src/index.js
CHANGED
|
@@ -19,6 +19,7 @@ export * from "./optimize/optimize.js";
|
|
|
19
19
|
export * from "./optimize/optimizer-run.js";
|
|
20
20
|
export * from "./optimize/reflect.js";
|
|
21
21
|
export * from "./providers/claude-p.js";
|
|
22
|
+
export * from "./providers/codex-p.js";
|
|
22
23
|
export * from "./providers/kiro-p.js";
|
|
23
24
|
export * from "./providers/models.js";
|
|
24
25
|
export * from "./scoring/calibration.js";
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { calculateCost, createAssistantMessageEventStream, createProvider, getCurrentSystemPrompt, getCurrentTools, } from "@earendil-works/pi-ai";
|
|
5
|
+
import { getBuiltinModels } from "@earendil-works/pi-ai/providers/all";
|
|
6
|
+
import { renderTranscript } from "./claude-p.js";
|
|
7
|
+
import { spawnGroup } from "./process-runner.js";
|
|
8
|
+
/** Provider id: models are referenced as `codex-p/<model>`, e.g. `codex-p/gpt-6-astra`. */
|
|
9
|
+
export const CODEX_P_PROVIDER = "codex-p";
|
|
10
|
+
const CODEX_P_API = "codex-p";
|
|
11
|
+
/** Environment variable naming the Codex executable; `codex` on the PATH otherwise. */
|
|
12
|
+
export const CODEX_P_COMMAND_ENV = "NEXO_CODEX_P_COMMAND";
|
|
13
|
+
/** `model_reasoning_effort` values passed through; pi's `minimal` maps to `low`, which every Codex model accepts. */
|
|
14
|
+
const EFFORTS = new Set(["low", "medium", "high", "xhigh"]);
|
|
15
|
+
/** Codex features that add tools or prompt sections. All are off, so the model sees only nexo's instructions and actions. */
|
|
16
|
+
const DISABLED_FEATURES = [
|
|
17
|
+
"shell_tool",
|
|
18
|
+
"unified_exec",
|
|
19
|
+
"code_mode",
|
|
20
|
+
"code_mode_host",
|
|
21
|
+
"apps",
|
|
22
|
+
"browser_use",
|
|
23
|
+
"computer_use",
|
|
24
|
+
"in_app_browser",
|
|
25
|
+
"image_generation",
|
|
26
|
+
"view_image",
|
|
27
|
+
"sleep_tool",
|
|
28
|
+
"skill_search",
|
|
29
|
+
"tool_suggest",
|
|
30
|
+
"multi_agent",
|
|
31
|
+
"goals",
|
|
32
|
+
"plugins",
|
|
33
|
+
"hooks",
|
|
34
|
+
"request_permissions_tool",
|
|
35
|
+
"default_mode_request_user_input",
|
|
36
|
+
];
|
|
37
|
+
/** `-c` overrides that drop Codex's own prompt sections (web search, skills, permissions, environment, apps, modes). */
|
|
38
|
+
const PROMPT_SECTIONS_OFF = [
|
|
39
|
+
'web_search="disabled"',
|
|
40
|
+
"skills.include_instructions=false",
|
|
41
|
+
"include_permissions_instructions=false",
|
|
42
|
+
"include_environment_context=false",
|
|
43
|
+
"include_apps_instructions=false",
|
|
44
|
+
"include_collaboration_mode_instructions=false",
|
|
45
|
+
];
|
|
46
|
+
/** Base instructions when the request has no system prompt; Codex's own would otherwise apply. */
|
|
47
|
+
const DEFAULT_INSTRUCTIONS = "You are a helpful assistant.";
|
|
48
|
+
/** The models pi-ai lists for ChatGPT-login Codex, re-homed under `codex-p`. */
|
|
49
|
+
function codexPModels() {
|
|
50
|
+
// `compat` holds OpenAI Responses quirks that do not apply to the codex-p api.
|
|
51
|
+
return getBuiltinModels("openai-codex").map(({ compat: _compat, ...m }) => ({
|
|
52
|
+
...m,
|
|
53
|
+
name: `${m.name} (codex exec)`,
|
|
54
|
+
api: CODEX_P_API,
|
|
55
|
+
provider: CODEX_P_PROVIDER,
|
|
56
|
+
baseUrl: "",
|
|
57
|
+
input: ["text"],
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
function plainSchema(tool) {
|
|
61
|
+
return JSON.parse(JSON.stringify(tool.parameters));
|
|
62
|
+
}
|
|
63
|
+
/** Developer-instructions section describing the tools and the `{ text, tool_calls }` reply the output schema enforces. */
|
|
64
|
+
export function codexToolsSection(tools) {
|
|
65
|
+
const defs = tools.map((t) => JSON.stringify({ name: t.name, description: t.description, parameters: plainSchema(t) })).join("\n");
|
|
66
|
+
return [
|
|
67
|
+
"# Actions",
|
|
68
|
+
"",
|
|
69
|
+
"Every reply must be one JSON object matching the response schema: `text` (what you say to the user, may be empty) and `tool_calls` (actions for the caller to run now, each `{ name, arguments_json }`, where `arguments_json` is a JSON-encoded object matching that action's parameters).",
|
|
70
|
+
"Do not run shell commands or use any tool of your own. The caller runs the actions you list and sends the results back in the next turn as <tool_result> entries. When you are finished, leave `tool_calls` empty and put the final answer in `text`.",
|
|
71
|
+
"Your own working directory is an empty scratch directory unrelated to the caller's. Never resolve paths against it: pass relative paths exactly as given, and use only absolute paths that the conversation itself names.",
|
|
72
|
+
"",
|
|
73
|
+
"Available actions, one JSON definition per line:",
|
|
74
|
+
defs,
|
|
75
|
+
].join("\n");
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Reply schema for `--output-schema`. Codex enforces OpenAI strict structured outputs, which reject optional
|
|
79
|
+
* properties, so arguments travel as a JSON string and are parsed here; pi validates them against the tool.
|
|
80
|
+
*/
|
|
81
|
+
export function codexReplySchema(tools) {
|
|
82
|
+
return {
|
|
83
|
+
type: "object",
|
|
84
|
+
properties: {
|
|
85
|
+
text: { type: "string" },
|
|
86
|
+
tool_calls: {
|
|
87
|
+
type: "array",
|
|
88
|
+
items: {
|
|
89
|
+
type: "object",
|
|
90
|
+
properties: { name: { type: "string", enum: tools.map((t) => t.name) }, arguments_json: { type: "string" } },
|
|
91
|
+
required: ["name", "arguments_json"],
|
|
92
|
+
additionalProperties: false,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
required: ["text", "tool_calls"],
|
|
97
|
+
additionalProperties: false,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
let callSeq = 0;
|
|
101
|
+
function toolCallId() {
|
|
102
|
+
callSeq = (callSeq + 1) % 1_000_000;
|
|
103
|
+
return `codex_p_${Date.now().toString(36)}_${callSeq}`;
|
|
104
|
+
}
|
|
105
|
+
/** Parses the final agent message of a tools turn. Unparseable arguments become `{}` so pi's validation reports them to the model. */
|
|
106
|
+
export function parseCodexReply(raw) {
|
|
107
|
+
let obj;
|
|
108
|
+
try {
|
|
109
|
+
obj = JSON.parse(raw);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return { text: raw, calls: [] };
|
|
113
|
+
}
|
|
114
|
+
const text = typeof obj?.text === "string" ? obj.text : "";
|
|
115
|
+
const calls = [];
|
|
116
|
+
if (Array.isArray(obj?.tool_calls)) {
|
|
117
|
+
for (const c of obj.tool_calls) {
|
|
118
|
+
if (typeof c?.name !== "string")
|
|
119
|
+
continue;
|
|
120
|
+
let args = c.arguments;
|
|
121
|
+
if (typeof c.arguments_json === "string") {
|
|
122
|
+
try {
|
|
123
|
+
args = JSON.parse(c.arguments_json);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
args = undefined;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const argObj = typeof args === "object" && args !== null && !Array.isArray(args) ? args : {};
|
|
130
|
+
calls.push({ type: "toolCall", id: toolCallId(), name: c.name, arguments: argObj });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return { text, calls };
|
|
134
|
+
}
|
|
135
|
+
/** Codex reports `input_tokens` including the cached part; pi counts them separately. */
|
|
136
|
+
function toUsage(model, u) {
|
|
137
|
+
const cached = u?.cached_input_tokens ?? 0;
|
|
138
|
+
const usage = {
|
|
139
|
+
input: Math.max(0, (u?.input_tokens ?? 0) - cached),
|
|
140
|
+
output: u?.output_tokens ?? 0,
|
|
141
|
+
cacheRead: cached,
|
|
142
|
+
cacheWrite: u?.cache_write_input_tokens ?? 0,
|
|
143
|
+
totalTokens: 0,
|
|
144
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
145
|
+
};
|
|
146
|
+
usage.totalTokens = usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
|
|
147
|
+
usage.cost = calculateCost(model, usage);
|
|
148
|
+
return usage;
|
|
149
|
+
}
|
|
150
|
+
function effortFlag(reasoning) {
|
|
151
|
+
if (!reasoning)
|
|
152
|
+
return undefined;
|
|
153
|
+
const effort = reasoning === "minimal" ? "low" : reasoning;
|
|
154
|
+
return EFFORTS.has(effort) ? effort : undefined;
|
|
155
|
+
}
|
|
156
|
+
function lastLine(text) {
|
|
157
|
+
return text.trim().split("\n").at(-1)?.trim() ?? "";
|
|
158
|
+
}
|
|
159
|
+
function isCatalog(value) {
|
|
160
|
+
return typeof value === "object" && value !== null && Array.isArray(value.models);
|
|
161
|
+
}
|
|
162
|
+
/** Loads the catalog the installed Codex CLI uses (about 1 s, no model call). */
|
|
163
|
+
async function readCatalog(run) {
|
|
164
|
+
const proc = run({ args: ["debug", "models"], stdin: "", cwd: tmpdir() });
|
|
165
|
+
const lines = [];
|
|
166
|
+
for await (const line of proc.lines)
|
|
167
|
+
lines.push(line);
|
|
168
|
+
const exit = await proc.exit;
|
|
169
|
+
let parsed;
|
|
170
|
+
try {
|
|
171
|
+
parsed = JSON.parse(lines.join("\n"));
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
parsed = undefined;
|
|
175
|
+
}
|
|
176
|
+
if (exit.code !== 0 || !isCatalog(parsed))
|
|
177
|
+
throw new Error(`codex debug models failed: ${lastLine(exit.stderr) || `exit code ${exit.code ?? "null"}`}`);
|
|
178
|
+
return parsed;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Rewrites the model's catalog entry so Codex sends only nexo's instructions and no tools of its own: `base_instructions`
|
|
182
|
+
* replaces Codex's 21k-char prompt, `direct_model_only` and `shell_type: disabled` drop the code-mode `exec` and shell
|
|
183
|
+
* tools, and removing `multi_agent_version` and `apply_patch_tool_type` drops the sub-agent and patch tools. These are
|
|
184
|
+
* undocumented catalog fields of Codex 0.167.2, found with `codex debug prompt-input`; a Codex update may rename them.
|
|
185
|
+
*/
|
|
186
|
+
export function strippedCatalog(catalog, slug, instructions) {
|
|
187
|
+
const entry = catalog.models.find((m) => m.slug === slug);
|
|
188
|
+
if (!entry)
|
|
189
|
+
throw new Error(`model ${slug} is not in the Codex CLI's model catalog (codex debug models)`);
|
|
190
|
+
const { multi_agent_version: _agents, model_messages: _messages, apply_patch_tool_type: _patch, ...rest } = entry;
|
|
191
|
+
const stripped = {
|
|
192
|
+
...rest,
|
|
193
|
+
base_instructions: instructions,
|
|
194
|
+
tool_mode: "direct_model_only",
|
|
195
|
+
shell_type: "disabled",
|
|
196
|
+
experimental_supported_tools: [],
|
|
197
|
+
supports_search_tool: false,
|
|
198
|
+
};
|
|
199
|
+
return { ...catalog, models: catalog.models.map((m) => (m === entry ? stripped : m)) };
|
|
200
|
+
}
|
|
201
|
+
function streamCodexP(run, getCatalog, model, context, options) {
|
|
202
|
+
const stream = createAssistantMessageEventStream();
|
|
203
|
+
const partial = {
|
|
204
|
+
role: "assistant",
|
|
205
|
+
content: [],
|
|
206
|
+
api: model.api,
|
|
207
|
+
provider: model.provider,
|
|
208
|
+
model: model.id,
|
|
209
|
+
usage: toUsage(model, undefined),
|
|
210
|
+
stopReason: "pending",
|
|
211
|
+
timestamp: Date.now(),
|
|
212
|
+
};
|
|
213
|
+
const snapshot = () => ({ ...partial, content: [...partial.content] });
|
|
214
|
+
const fail = (reason, message, usage) => {
|
|
215
|
+
const error = { ...snapshot(), stopReason: reason, errorMessage: message, ...(usage ? { usage } : {}) };
|
|
216
|
+
stream.push({ type: "error", reason, error });
|
|
217
|
+
stream.end(error);
|
|
218
|
+
};
|
|
219
|
+
const emitText = (text) => {
|
|
220
|
+
const contentIndex = partial.content.length;
|
|
221
|
+
partial.content.push({ type: "text", text });
|
|
222
|
+
stream.push({ type: "text_start", contentIndex, partial: snapshot() });
|
|
223
|
+
stream.push({ type: "text_delta", contentIndex, delta: text, partial: snapshot() });
|
|
224
|
+
stream.push({ type: "text_end", contentIndex, content: text, partial: snapshot() });
|
|
225
|
+
};
|
|
226
|
+
const emitThinking = (thinking) => {
|
|
227
|
+
const contentIndex = partial.content.length;
|
|
228
|
+
partial.content.push({ type: "thinking", thinking });
|
|
229
|
+
stream.push({ type: "thinking_start", contentIndex, partial: snapshot() });
|
|
230
|
+
stream.push({ type: "thinking_delta", contentIndex, delta: thinking, partial: snapshot() });
|
|
231
|
+
stream.push({ type: "thinking_end", contentIndex, content: thinking, partial: snapshot() });
|
|
232
|
+
};
|
|
233
|
+
const emitCall = (call) => {
|
|
234
|
+
const contentIndex = partial.content.length;
|
|
235
|
+
partial.content.push({ ...call, arguments: {} });
|
|
236
|
+
stream.push({ type: "toolcall_start", contentIndex, partial: snapshot() });
|
|
237
|
+
partial.content[contentIndex] = call;
|
|
238
|
+
stream.push({ type: "toolcall_delta", contentIndex, delta: JSON.stringify(call.arguments), partial: snapshot() });
|
|
239
|
+
stream.push({ type: "toolcall_end", contentIndex, toolCall: call, partial: snapshot() });
|
|
240
|
+
};
|
|
241
|
+
queueMicrotask(async () => {
|
|
242
|
+
const signal = options?.signal;
|
|
243
|
+
if (signal?.aborted)
|
|
244
|
+
return fail("aborted", "Request was aborted");
|
|
245
|
+
const tools = getCurrentTools(context.messages);
|
|
246
|
+
const useTools = tools.length > 0 && options?.toolChoice !== "none";
|
|
247
|
+
const instructions = [getCurrentSystemPrompt(context.messages), useTools ? codexToolsSection(tools) : ""].filter((s) => s.length > 0).join("\n\n");
|
|
248
|
+
let dir;
|
|
249
|
+
try {
|
|
250
|
+
dir = await mkdtemp(join(tmpdir(), "nexo-codex-p-"));
|
|
251
|
+
const catalogFile = join(dir, "model-catalog.json");
|
|
252
|
+
await writeFile(catalogFile, JSON.stringify(strippedCatalog(await getCatalog(), model.id, instructions || DEFAULT_INSTRUCTIONS)), "utf8");
|
|
253
|
+
// Codex's tools and prompt sections are stripped; the empty temp dir under a read-only sandbox, with no user config
|
|
254
|
+
// or exec rules, stays as a second layer.
|
|
255
|
+
const args = ["exec", "--json", "--ephemeral", "--skip-git-repo-check", "--ignore-user-config", "--ignore-rules", "-s", "read-only", "-C", dir, "-m", model.id];
|
|
256
|
+
const effort = effortFlag(options?.reasoning);
|
|
257
|
+
if (effort)
|
|
258
|
+
args.push("-c", `model_reasoning_effort=${JSON.stringify(effort)}`);
|
|
259
|
+
// A JSON string literal is also a valid TOML basic string, which is how `-c` parses the value.
|
|
260
|
+
args.push("-c", `model_catalog_json=${JSON.stringify(catalogFile)}`);
|
|
261
|
+
for (const override of PROMPT_SECTIONS_OFF)
|
|
262
|
+
args.push("-c", override);
|
|
263
|
+
for (const feature of DISABLED_FEATURES)
|
|
264
|
+
args.push("--disable", feature);
|
|
265
|
+
if (useTools) {
|
|
266
|
+
const file = join(dir, "reply-schema.json");
|
|
267
|
+
await writeFile(file, JSON.stringify(codexReplySchema(tools)), "utf8");
|
|
268
|
+
args.push("--output-schema", file);
|
|
269
|
+
}
|
|
270
|
+
args.push("-");
|
|
271
|
+
const proc = run({ args, stdin: renderTranscript(context.messages), cwd: dir, ...(signal ? { signal } : {}) });
|
|
272
|
+
stream.push({ type: "start", partial: snapshot() });
|
|
273
|
+
let rawUsage;
|
|
274
|
+
let completed = false;
|
|
275
|
+
let turnFailed;
|
|
276
|
+
let lastError;
|
|
277
|
+
let finalMessage;
|
|
278
|
+
for await (const line of proc.lines) {
|
|
279
|
+
if (!line.trim())
|
|
280
|
+
continue;
|
|
281
|
+
let event;
|
|
282
|
+
try {
|
|
283
|
+
event = JSON.parse(line);
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (event.type === "item.completed" && event.item) {
|
|
289
|
+
const { type, text } = event.item;
|
|
290
|
+
if (type === "reasoning" && text)
|
|
291
|
+
emitThinking(text);
|
|
292
|
+
else if (type === "agent_message" && typeof text === "string") {
|
|
293
|
+
if (useTools)
|
|
294
|
+
finalMessage = text;
|
|
295
|
+
else if (text)
|
|
296
|
+
emitText(text);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
else if (event.type === "turn.completed") {
|
|
300
|
+
completed = true;
|
|
301
|
+
rawUsage = event.usage;
|
|
302
|
+
}
|
|
303
|
+
else if (event.type === "turn.failed")
|
|
304
|
+
turnFailed = event.error?.message ?? "turn failed";
|
|
305
|
+
else if (event.type === "error" && event.message)
|
|
306
|
+
lastError = event.message;
|
|
307
|
+
}
|
|
308
|
+
const exit = await proc.exit;
|
|
309
|
+
if (signal?.aborted)
|
|
310
|
+
return fail("aborted", "Request was aborted");
|
|
311
|
+
const usage = toUsage(model, rawUsage);
|
|
312
|
+
if (turnFailed || !completed) {
|
|
313
|
+
const detail = turnFailed ?? lastError ?? (lastLine(exit.stderr) || `exited with code ${exit.code ?? "null"} without completing a turn`);
|
|
314
|
+
return fail("error", `codex exec failed: ${detail}`, usage);
|
|
315
|
+
}
|
|
316
|
+
let stopReason = "stop";
|
|
317
|
+
if (useTools && finalMessage !== undefined) {
|
|
318
|
+
const { text, calls } = parseCodexReply(finalMessage);
|
|
319
|
+
if (text)
|
|
320
|
+
emitText(text);
|
|
321
|
+
for (const call of calls)
|
|
322
|
+
emitCall(call);
|
|
323
|
+
if (calls.length > 0)
|
|
324
|
+
stopReason = "toolUse";
|
|
325
|
+
}
|
|
326
|
+
const message = { ...snapshot(), usage, stopReason };
|
|
327
|
+
stream.push({ type: "done", reason: stopReason, message });
|
|
328
|
+
stream.end(message);
|
|
329
|
+
}
|
|
330
|
+
catch (error) {
|
|
331
|
+
if (signal?.aborted)
|
|
332
|
+
return fail("aborted", "Request was aborted");
|
|
333
|
+
fail("error", `codex exec failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
334
|
+
}
|
|
335
|
+
finally {
|
|
336
|
+
if (dir)
|
|
337
|
+
await rm(dir, { recursive: true, force: true }).catch(() => { });
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
return stream;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Runs OpenAI models through the local Codex CLI (`codex exec`), authenticated by whatever login the CLI has (a ChatGPT
|
|
344
|
+
* plan or its own API key), so no nexo key is needed. Codex's own prompt and tools are stripped through a patched model
|
|
345
|
+
* catalog (see `strippedCatalog`), so the system prompt reaches the model as its base instructions. When the request carries nexo tools, the reply is constrained by
|
|
346
|
+
* `--output-schema` to `{ text, tool_calls }` and returned as real tool calls; turns arrive whole, since `codex exec`
|
|
347
|
+
* emits each message only when it completes.
|
|
348
|
+
*/
|
|
349
|
+
export function codexPProvider(options = {}) {
|
|
350
|
+
const command = options.command ?? process.env[CODEX_P_COMMAND_ENV] ?? "codex";
|
|
351
|
+
const run = options.run ?? ((request) => spawnGroup(command, request));
|
|
352
|
+
const load = options.catalog ?? (() => readCatalog(run));
|
|
353
|
+
// Loaded once per provider; a failed load is retried on the next call.
|
|
354
|
+
let cached;
|
|
355
|
+
const getCatalog = () => {
|
|
356
|
+
cached ??= load().catch((error) => {
|
|
357
|
+
cached = undefined;
|
|
358
|
+
throw error;
|
|
359
|
+
});
|
|
360
|
+
return cached;
|
|
361
|
+
};
|
|
362
|
+
const api = {
|
|
363
|
+
stream: (model, context, opts) => streamCodexP(run, getCatalog, model, context, opts),
|
|
364
|
+
streamSimple: (model, context, opts) => streamCodexP(run, getCatalog, model, context, opts),
|
|
365
|
+
};
|
|
366
|
+
return createProvider({
|
|
367
|
+
id: CODEX_P_PROVIDER,
|
|
368
|
+
name: "Codex CLI (codex exec)",
|
|
369
|
+
auth: {
|
|
370
|
+
apiKey: {
|
|
371
|
+
name: "Codex CLI login",
|
|
372
|
+
resolve: async () => ({ auth: {}, source: "codex CLI login" }),
|
|
373
|
+
},
|
|
374
|
+
},
|
|
375
|
+
models: codexPModels(),
|
|
376
|
+
api,
|
|
377
|
+
});
|
|
378
|
+
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { builtinModels } from "@earendil-works/pi-ai/providers/all";
|
|
2
2
|
import { claudePProvider } from "./claude-p.js";
|
|
3
|
+
import { codexPProvider } from "./codex-p.js";
|
|
3
4
|
import { kiroPProvider } from "./kiro-p.js";
|
|
4
|
-
/** pi-ai's built-in providers plus nexo's own (`claude-p`, `kiro-p`). */
|
|
5
|
+
/** pi-ai's built-in providers plus nexo's own (`claude-p`, `codex-p`, `kiro-p`). */
|
|
5
6
|
export function nexoModels() {
|
|
6
7
|
const models = builtinModels();
|
|
7
8
|
models.setProvider(claudePProvider());
|
|
9
|
+
models.setProvider(codexPProvider());
|
|
8
10
|
models.setProvider(kiroPProvider());
|
|
9
11
|
return models;
|
|
10
12
|
}
|
|
@@ -255,10 +255,12 @@ export class Session {
|
|
|
255
255
|
steer(text) {
|
|
256
256
|
if (!this.busy || !text.trim())
|
|
257
257
|
return false;
|
|
258
|
+
// Same `@file` attachment as a typed turn, so the agent gets the contents instead of reading the file itself.
|
|
259
|
+
const sent = expandMentions(text, this.state.cwd).text;
|
|
258
260
|
if (this.steerCtl)
|
|
259
|
-
this.steerCtl.steer(
|
|
261
|
+
this.steerCtl.steer(sent);
|
|
260
262
|
else
|
|
261
|
-
this.steerPending.push(
|
|
263
|
+
this.steerPending.push(sent);
|
|
262
264
|
return true;
|
|
263
265
|
}
|
|
264
266
|
/** Drops steered messages the running turn has not taken yet. */
|
|
@@ -4,6 +4,7 @@ import { createMutableRedactor, createRedactor, createSecretSet, containsSecret,
|
|
|
4
4
|
import { configErrors, deepMerge, loadConfig } from "../config/load.js";
|
|
5
5
|
import { EDITABLE_SETTINGS, findSetting, mergedLayers, parseSettingInput, readConfigLayers, resetSetting, settingView, writeSetting, } from "./config-edit.js";
|
|
6
6
|
import { CLAUDE_P_PROVIDER } from "../providers/claude-p.js";
|
|
7
|
+
import { CODEX_P_PROVIDER } from "../providers/codex-p.js";
|
|
7
8
|
import { KIRO_P_PROVIDER } from "../providers/kiro-p.js";
|
|
8
9
|
import { readCredentials, writeCredentials } from "./credentials.js";
|
|
9
10
|
/** What pi-ai's `getEnvApiKey` returns for ambient credentials (Google ADC, AWS profiles) instead of a key. */
|
|
@@ -142,8 +143,8 @@ export function createSettings(options) {
|
|
|
142
143
|
const purpose = isSearchProvider(provider) ? "search" : isBrowserProfileKey(provider) ? "browser" : "model";
|
|
143
144
|
if (optionKeys.has(provider))
|
|
144
145
|
return { provider, purpose, state: "option", envVar: null, last4: null, inFile };
|
|
145
|
-
// claude-p and kiro-p run a local CLI that brings its own login: ambient credentials, like AWS or Google ADC.
|
|
146
|
-
if (provider === CLAUDE_P_PROVIDER || provider === KIRO_P_PROVIDER)
|
|
146
|
+
// claude-p, codex-p and kiro-p run a local CLI that brings its own login: ambient credentials, like AWS or Google ADC.
|
|
147
|
+
if (provider === CLAUDE_P_PROVIDER || provider === CODEX_P_PROVIDER || provider === KIRO_P_PROVIDER)
|
|
147
148
|
return { provider, purpose, state: "env", envVar: null, last4: null, inFile };
|
|
148
149
|
if (envKey(provider) !== undefined)
|
|
149
150
|
return { provider, purpose, state: "env", envVar: envVarOf(provider), last4: null, inFile };
|