@h-rig/provider-plugin 0.0.6-alpha.157 → 0.0.6-alpha.159
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/dist/bin/rig-agent-dispatch.d.ts +2 -0
- package/dist/bin/rig-agent-dispatch.js +863 -0
- package/dist/src/agent-harness/agent-mode.d.ts +1 -0
- package/dist/src/agent-harness/agent-mode.js +48 -0
- package/dist/src/agent-harness/agent-wrapper.d.ts +53 -0
- package/dist/src/agent-harness/agent-wrapper.js +916 -0
- package/dist/src/agent-harness/controlled-bash.d.ts +3 -0
- package/dist/src/agent-harness/controlled-bash.js +45 -0
- package/dist/src/agent-harness/git-ops.d.ts +2 -0
- package/dist/src/agent-harness/git-ops.js +27 -0
- package/dist/src/agent-harness/repo-ops.d.ts +8 -0
- package/dist/src/agent-harness/repo-ops.js +471 -0
- package/dist/src/agent-harness/rig-agent-entrypoint.d.ts +1 -0
- package/dist/src/agent-harness/rig-agent-entrypoint.js +1277 -0
- package/dist/src/agent-harness/rig-agent.d.ts +2 -0
- package/dist/src/agent-harness/rig-agent.js +1244 -0
- package/dist/src/agent-harness/runtime-snapshot-config.d.ts +2 -0
- package/dist/src/agent-harness/runtime-snapshot-config.js +25 -0
- package/dist/src/agent-harness/task-data.d.ts +2 -0
- package/dist/src/agent-harness/task-data.js +12 -0
- package/dist/src/agent-harness/task-ops.d.ts +10 -0
- package/dist/src/agent-harness/task-ops.js +53 -0
- package/dist/src/index.js +3366 -16
- package/dist/src/pi-settings-materializer.d.ts +10 -0
- package/dist/src/pi-settings-materializer.js +52 -0
- package/dist/src/plugin.d.ts +9 -2
- package/dist/src/plugin.js +3360 -8
- package/dist/src/service.d.ts +1 -1
- package/dist/src/session-asset-materializer-service.d.ts +13 -0
- package/dist/src/session-asset-materializer-service.js +124 -0
- package/dist/src/skill-materializer.d.ts +25 -0
- package/dist/src/skill-materializer.js +46 -0
- package/dist/src/tooling/binary-build-worker.d.ts +1 -0
- package/dist/src/tooling/binary-build-worker.js +323 -0
- package/dist/src/tooling/browser-tool-entrypoint.d.ts +2 -0
- package/dist/src/tooling/browser-tool-entrypoint.js +125 -0
- package/dist/src/tooling/browser-tools.d.ts +3 -0
- package/dist/src/tooling/browser-tools.js +27 -0
- package/dist/src/tooling/claude-router-binary.d.ts +3 -0
- package/dist/src/tooling/claude-router-binary.js +381 -0
- package/dist/src/tooling/claude-router.d.ts +22 -0
- package/dist/src/tooling/claude-router.js +524 -0
- package/dist/src/tooling/embedded-native-assets.d.ts +7 -0
- package/dist/src/tooling/embedded-native-assets.js +6 -0
- package/dist/src/tooling/file-tools.d.ts +5 -0
- package/dist/src/tooling/file-tools.js +224 -0
- package/dist/src/tooling/gateway.d.ts +4 -0
- package/dist/src/tooling/gateway.js +430 -0
- package/dist/src/tooling/native-extract.d.ts +2 -0
- package/dist/src/tooling/native-extract.js +44 -0
- package/dist/src/tooling/runtime-binary-build.d.ts +88 -0
- package/dist/src/tooling/runtime-binary-build.js +480 -0
- package/dist/src/tooling/shell-tools.d.ts +5 -0
- package/dist/src/tooling/shell-tools.js +217 -0
- package/native/darwin-arm64/rig-shell +0 -0
- package/native/darwin-arm64/rig-shell.build-manifest.json +4 -0
- package/native/darwin-arm64/rig-tools +0 -0
- package/native/darwin-arm64/rig-tools.build-manifest.json +4 -0
- package/native/darwin-x64/rig-shell +0 -0
- package/native/darwin-x64/rig-tools +0 -0
- package/native/linux-arm64/rig-shell +0 -0
- package/native/linux-arm64/rig-tools +0 -0
- package/native/linux-x64/rig-shell +0 -0
- package/native/linux-x64/rig-tools +0 -0
- package/native/win32-x64/rig-shell.exe +0 -0
- package/native/win32-x64/rig-tools.exe +0 -0
- package/package.json +54 -5
- package/dist/src/claude-stream-records.d.ts +0 -24
- package/dist/src/claude-stream-records.js +0 -158
- package/dist/src/codex-app-server.d.ts +0 -16
- package/dist/src/codex-app-server.js +0 -548
- package/dist/src/codex-exec-records.d.ts +0 -27
- package/dist/src/codex-exec-records.js +0 -203
|
@@ -1,548 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// packages/provider-plugin/src/codex-app-server.ts
|
|
3
|
-
import { spawn } from "child_process";
|
|
4
|
-
import { createInterface } from "readline";
|
|
5
|
-
import { invokeRuntimeTool, CLAUDE_ROUTER_TOOL_DEFINITIONS } from "@rig/runtime/control-plane/runtime/tooling/claude-router";
|
|
6
|
-
var CODEX_APP_SERVER_TASK_RUN_SENTINEL = "__rig_codex_app_server_task_run__";
|
|
7
|
-
var RIG_DYNAMIC_TOOL_SERVER = "rig_runtime_tools";
|
|
8
|
-
var DEFAULT_CLIENT_INFO = {
|
|
9
|
-
name: "rig_task_runtime",
|
|
10
|
-
title: "Rig Task Runtime",
|
|
11
|
-
version: "0.1.0"
|
|
12
|
-
};
|
|
13
|
-
var CODEX_APP_SERVER_DISABLED_FEATURES = [
|
|
14
|
-
"shell_tool",
|
|
15
|
-
"apply_patch_freeform",
|
|
16
|
-
"request_permissions_tool",
|
|
17
|
-
"apps",
|
|
18
|
-
"plugins",
|
|
19
|
-
"tool_search",
|
|
20
|
-
"js_repl",
|
|
21
|
-
"js_repl_tools_only",
|
|
22
|
-
"collab"
|
|
23
|
-
];
|
|
24
|
-
function buildCodexAppServerArgs() {
|
|
25
|
-
return [
|
|
26
|
-
"app-server",
|
|
27
|
-
...CODEX_APP_SERVER_DISABLED_FEATURES.flatMap((feature) => ["--disable", feature]),
|
|
28
|
-
"-c",
|
|
29
|
-
'web_search="disabled"',
|
|
30
|
-
"-c",
|
|
31
|
-
"tools.view_image=false",
|
|
32
|
-
"-c",
|
|
33
|
-
"features.default_mode_request_user_input=false"
|
|
34
|
-
];
|
|
35
|
-
}
|
|
36
|
-
function parseCodexAppServerTaskRunArgs(argv) {
|
|
37
|
-
if (argv[0] !== CODEX_APP_SERVER_TASK_RUN_SENTINEL) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
let model;
|
|
41
|
-
let prompt;
|
|
42
|
-
let runtimeMode = "workspace-write";
|
|
43
|
-
let interactionMode;
|
|
44
|
-
for (let index = 1;index < argv.length; index += 1) {
|
|
45
|
-
const current = argv[index];
|
|
46
|
-
if (current === "--model") {
|
|
47
|
-
model = argv[index + 1];
|
|
48
|
-
index += 1;
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
if (current === "--runtime-mode") {
|
|
52
|
-
runtimeMode = argv[index + 1] ?? runtimeMode;
|
|
53
|
-
index += 1;
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
if (current === "--interaction-mode") {
|
|
57
|
-
interactionMode = argv[index + 1];
|
|
58
|
-
index += 1;
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
if (current === "--prompt") {
|
|
62
|
-
prompt = argv[index + 1];
|
|
63
|
-
index += 1;
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (!prompt?.trim()) {
|
|
68
|
-
throw new Error("Missing `--prompt` for Codex app-server task run.");
|
|
69
|
-
}
|
|
70
|
-
return {
|
|
71
|
-
model: model?.trim() ? model.trim() : undefined,
|
|
72
|
-
prompt,
|
|
73
|
-
runtimeMode,
|
|
74
|
-
interactionMode
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
async function runCodexAppServerTaskRun(options) {
|
|
78
|
-
const child = spawn(options.codexBinary, options.launchArgs, {
|
|
79
|
-
cwd: options.cwd,
|
|
80
|
-
env: sanitizeEnv(options.env),
|
|
81
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
82
|
-
});
|
|
83
|
-
const pendingResponses = new Map;
|
|
84
|
-
const dynamicToolResults = new Map;
|
|
85
|
-
const agentMessageText = new Map;
|
|
86
|
-
const inFlightToolCalls = new Set;
|
|
87
|
-
let nextRequestId = 1;
|
|
88
|
-
let sendQueue = Promise.resolve();
|
|
89
|
-
const completionState = { current: null };
|
|
90
|
-
const stdout = createInterface({ input: child.stdout });
|
|
91
|
-
const stderr = createInterface({ input: child.stderr });
|
|
92
|
-
const sendMessage = (payload) => {
|
|
93
|
-
const line = `${JSON.stringify(payload)}
|
|
94
|
-
`;
|
|
95
|
-
sendQueue = sendQueue.then(() => writeChildLine(child, line));
|
|
96
|
-
return sendQueue;
|
|
97
|
-
};
|
|
98
|
-
const sendRequest = async (method, params) => {
|
|
99
|
-
const id = nextRequestId;
|
|
100
|
-
nextRequestId += 1;
|
|
101
|
-
const resultPromise = new Promise((resolve, reject) => {
|
|
102
|
-
pendingResponses.set(id, { resolve, reject });
|
|
103
|
-
});
|
|
104
|
-
await sendMessage({ id, method, params });
|
|
105
|
-
return resultPromise;
|
|
106
|
-
};
|
|
107
|
-
const sendResponse = async (id, result) => {
|
|
108
|
-
await sendMessage({ id, result });
|
|
109
|
-
};
|
|
110
|
-
const sendError = async (id, message) => {
|
|
111
|
-
await sendMessage({
|
|
112
|
-
id,
|
|
113
|
-
error: {
|
|
114
|
-
code: -32603,
|
|
115
|
-
message
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
};
|
|
119
|
-
const trackToolCall = (call) => {
|
|
120
|
-
inFlightToolCalls.add(call);
|
|
121
|
-
call.finally(() => inFlightToolCalls.delete(call)).catch((err) => {
|
|
122
|
-
console.warn("[codex-app-server] in-flight tool call failure:", err);
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
const handleNotification = (message) => {
|
|
126
|
-
const method = message.method;
|
|
127
|
-
if (!method) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
const params = message.params ?? {};
|
|
131
|
-
const timestamp = new Date().toISOString();
|
|
132
|
-
if (method === "thread/started") {
|
|
133
|
-
emitSyntheticCodexRecord({
|
|
134
|
-
type: "thread.started",
|
|
135
|
-
timestamp,
|
|
136
|
-
thread: params.thread ?? null
|
|
137
|
-
});
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
if (method === "turn/started") {
|
|
141
|
-
emitSyntheticCodexRecord({
|
|
142
|
-
type: "turn.started",
|
|
143
|
-
timestamp,
|
|
144
|
-
turn: params.turn ?? null
|
|
145
|
-
});
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
if (method === "item/agentMessage/delta") {
|
|
149
|
-
const itemId = normalizeString(params.itemId);
|
|
150
|
-
const delta = typeof params.delta === "string" ? params.delta : "";
|
|
151
|
-
if (!itemId || delta.length === 0) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
agentMessageText.set(itemId, `${agentMessageText.get(itemId) ?? ""}${delta}`);
|
|
155
|
-
emitSyntheticCodexRecord({
|
|
156
|
-
type: "stream_event",
|
|
157
|
-
event: {
|
|
158
|
-
delta: {
|
|
159
|
-
type: "text_delta",
|
|
160
|
-
text: delta
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
if (method === "item/started" || method === "item/completed") {
|
|
167
|
-
const record = mapAppServerItemToCodexRecord({
|
|
168
|
-
phase: method === "item/started" ? "item.started" : "item.completed",
|
|
169
|
-
timestamp,
|
|
170
|
-
item: params.item,
|
|
171
|
-
dynamicToolResults,
|
|
172
|
-
agentMessageText
|
|
173
|
-
});
|
|
174
|
-
if (record) {
|
|
175
|
-
emitSyntheticCodexRecord(record);
|
|
176
|
-
}
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
if (method === "turn/completed") {
|
|
180
|
-
const turn = asRecord(params.turn);
|
|
181
|
-
const error = asRecord(turn?.error);
|
|
182
|
-
completionState.current = {
|
|
183
|
-
status: normalizeString(turn?.status) ?? "failed",
|
|
184
|
-
error: normalizeString(error?.message)
|
|
185
|
-
};
|
|
186
|
-
emitSyntheticCodexRecord({
|
|
187
|
-
type: "turn.completed",
|
|
188
|
-
timestamp,
|
|
189
|
-
turn
|
|
190
|
-
});
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
if (method === "error") {
|
|
194
|
-
const errorMessage = normalizeString(params.message) ?? JSON.stringify(params);
|
|
195
|
-
console.error(`[rig-codex-app-server] ${errorMessage}`);
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
const handleServerRequest = (message) => {
|
|
199
|
-
const method = message.method;
|
|
200
|
-
const requestId = message.id;
|
|
201
|
-
if (!method || requestId === undefined) {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
if (method === "item/tool/call") {
|
|
205
|
-
const params = message.params ?? {};
|
|
206
|
-
const callId = normalizeString(params.callId);
|
|
207
|
-
const toolName = normalizeString(params.tool);
|
|
208
|
-
const toolArgs = asRecord(params.arguments) ?? {};
|
|
209
|
-
const toolCall = (async () => {
|
|
210
|
-
if (!callId || !toolName) {
|
|
211
|
-
await sendError(requestId, "Malformed dynamic tool call.");
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
try {
|
|
215
|
-
const invocation = await invokeRuntimeTool(toolName, toolArgs, {
|
|
216
|
-
env: options.env
|
|
217
|
-
});
|
|
218
|
-
const contentItems = invocationToContentItems(invocation);
|
|
219
|
-
const contentText = contentItems.filter((item) => item.type === "inputText").map((item) => item.text).join(`
|
|
220
|
-
`).trim();
|
|
221
|
-
dynamicToolResults.set(callId, {
|
|
222
|
-
isError: invocation.isError === true,
|
|
223
|
-
contentText,
|
|
224
|
-
structuredResult: asRecord(invocation.structuredContent) ?? (contentText ? { content: contentText } : null)
|
|
225
|
-
});
|
|
226
|
-
await sendResponse(requestId, {
|
|
227
|
-
contentItems,
|
|
228
|
-
success: invocation.isError !== true
|
|
229
|
-
});
|
|
230
|
-
} catch (error) {
|
|
231
|
-
const messageText = error instanceof Error ? error.message : String(error);
|
|
232
|
-
dynamicToolResults.set(callId, {
|
|
233
|
-
isError: true,
|
|
234
|
-
contentText: messageText,
|
|
235
|
-
structuredResult: { error: messageText }
|
|
236
|
-
});
|
|
237
|
-
await sendResponse(requestId, {
|
|
238
|
-
contentItems: [{ type: "inputText", text: messageText }],
|
|
239
|
-
success: false
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
})();
|
|
243
|
-
trackToolCall(toolCall);
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
if (method === "item/commandExecution/requestApproval" || method === "item/fileChange/requestApproval") {
|
|
247
|
-
trackToolCall(sendResponse(requestId, { decision: "decline" }));
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
if (method === "item/permissions/requestApproval") {
|
|
251
|
-
trackToolCall(sendResponse(requestId, {
|
|
252
|
-
permissions: {},
|
|
253
|
-
scope: "turn"
|
|
254
|
-
}));
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
if (method === "applyPatchApproval" || method === "execCommandApproval") {
|
|
258
|
-
trackToolCall(sendResponse(requestId, { decision: "denied" }));
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
trackToolCall(sendError(requestId, `Unsupported app-server request: ${method}`));
|
|
262
|
-
};
|
|
263
|
-
stdout.on("line", (line) => {
|
|
264
|
-
const trimmed = line.trim();
|
|
265
|
-
if (!trimmed) {
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
let message;
|
|
269
|
-
try {
|
|
270
|
-
message = JSON.parse(trimmed);
|
|
271
|
-
} catch {
|
|
272
|
-
console.error(trimmed);
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
if (message.method) {
|
|
276
|
-
if (message.id !== undefined) {
|
|
277
|
-
handleServerRequest(message);
|
|
278
|
-
} else {
|
|
279
|
-
handleNotification(message);
|
|
280
|
-
}
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
if (message.id !== undefined) {
|
|
284
|
-
const pending = pendingResponses.get(message.id);
|
|
285
|
-
if (!pending) {
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
pendingResponses.delete(message.id);
|
|
289
|
-
if (message.error) {
|
|
290
|
-
pending.reject(new Error(formatJsonRpcError(message.error)));
|
|
291
|
-
} else {
|
|
292
|
-
pending.resolve(message.result ?? {});
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
stderr.on("line", (line) => {
|
|
297
|
-
if (line.trim()) {
|
|
298
|
-
console.error(line);
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
const exitPromise = new Promise((resolve) => {
|
|
302
|
-
child.once("close", (code, signal) => resolve({ code, signal }));
|
|
303
|
-
});
|
|
304
|
-
await sendRequest("initialize", {
|
|
305
|
-
clientInfo: DEFAULT_CLIENT_INFO,
|
|
306
|
-
capabilities: {
|
|
307
|
-
experimentalApi: true
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
await sendMessage({
|
|
311
|
-
method: "initialized",
|
|
312
|
-
params: {}
|
|
313
|
-
});
|
|
314
|
-
const threadStart = await sendRequest("thread/start", {
|
|
315
|
-
model: options.config.model ?? null,
|
|
316
|
-
cwd: options.cwd,
|
|
317
|
-
approvalPolicy: "never",
|
|
318
|
-
sandbox: options.config.runtimeMode === "full-access" ? "danger-full-access" : "workspace-write",
|
|
319
|
-
serviceName: "rig_task_runtime",
|
|
320
|
-
experimentalRawEvents: false,
|
|
321
|
-
persistExtendedHistory: false,
|
|
322
|
-
dynamicTools: codexDynamicToolDefinitions()
|
|
323
|
-
});
|
|
324
|
-
const thread = asRecord(threadStart.thread);
|
|
325
|
-
const threadId = normalizeString(thread?.id);
|
|
326
|
-
if (!threadId) {
|
|
327
|
-
throw new Error("Codex app-server thread/start did not return a thread id.");
|
|
328
|
-
}
|
|
329
|
-
await sendRequest("turn/start", {
|
|
330
|
-
threadId,
|
|
331
|
-
input: [
|
|
332
|
-
{
|
|
333
|
-
type: "text",
|
|
334
|
-
text: options.config.prompt,
|
|
335
|
-
text_elements: []
|
|
336
|
-
}
|
|
337
|
-
]
|
|
338
|
-
});
|
|
339
|
-
let exitResult = null;
|
|
340
|
-
while (!completionState.current) {
|
|
341
|
-
exitResult = await Promise.race([
|
|
342
|
-
exitPromise,
|
|
343
|
-
new Promise((resolve) => setTimeout(() => resolve(null), 100))
|
|
344
|
-
]);
|
|
345
|
-
if (exitResult) {
|
|
346
|
-
break;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
const completedTurn = completionState.current;
|
|
350
|
-
if (!completedTurn) {
|
|
351
|
-
const detail = exitResult ? `codex app-server exited before turn completion (${String(exitResult.code ?? exitResult.signal ?? "unknown")})` : "codex app-server exited before turn completion";
|
|
352
|
-
throw new Error(detail);
|
|
353
|
-
}
|
|
354
|
-
if (inFlightToolCalls.size > 0) {
|
|
355
|
-
await Promise.allSettled(Array.from(inFlightToolCalls));
|
|
356
|
-
}
|
|
357
|
-
terminateChild(child);
|
|
358
|
-
await exitPromise;
|
|
359
|
-
if (completedTurn.status !== "completed") {
|
|
360
|
-
const reason = completedTurn.error ?? `Codex turn ended with status ${completedTurn.status}`;
|
|
361
|
-
console.error(`[rig-codex-app-server] ${reason}`);
|
|
362
|
-
return 1;
|
|
363
|
-
}
|
|
364
|
-
return 0;
|
|
365
|
-
}
|
|
366
|
-
function codexDynamicToolDefinitions() {
|
|
367
|
-
return [
|
|
368
|
-
{
|
|
369
|
-
name: "shell",
|
|
370
|
-
description: "Run a shell command through Rig's audited gateway inside the current task workspace. Use this for git, bun, node, python3, rg, and related command-line work. Never rely on absolute host binaries.",
|
|
371
|
-
inputSchema: {
|
|
372
|
-
type: "object",
|
|
373
|
-
properties: {
|
|
374
|
-
command: { type: "string", description: "Shell command to execute." },
|
|
375
|
-
workdir: { type: "string", description: "Optional workspace-relative working directory." },
|
|
376
|
-
shell: { type: "string", enum: ["bash", "sh", "zsh"] }
|
|
377
|
-
},
|
|
378
|
-
required: ["command"],
|
|
379
|
-
additionalProperties: false
|
|
380
|
-
}
|
|
381
|
-
},
|
|
382
|
-
...CLAUDE_ROUTER_TOOL_DEFINITIONS
|
|
383
|
-
];
|
|
384
|
-
}
|
|
385
|
-
function mapAppServerItemToCodexRecord(input) {
|
|
386
|
-
const item = asRecord(input.item);
|
|
387
|
-
const itemType = normalizeString(item?.type);
|
|
388
|
-
const itemId = normalizeString(item?.id);
|
|
389
|
-
if (!item || !itemType || !itemId) {
|
|
390
|
-
return null;
|
|
391
|
-
}
|
|
392
|
-
if (itemType === "agentMessage") {
|
|
393
|
-
if (input.phase !== "item.completed") {
|
|
394
|
-
return null;
|
|
395
|
-
}
|
|
396
|
-
const finalText = normalizeString(item.text) ?? input.agentMessageText.get(itemId) ?? "";
|
|
397
|
-
input.agentMessageText.delete(itemId);
|
|
398
|
-
return {
|
|
399
|
-
type: "item.completed",
|
|
400
|
-
timestamp: input.timestamp,
|
|
401
|
-
item: {
|
|
402
|
-
id: itemId,
|
|
403
|
-
type: "agent_message",
|
|
404
|
-
text: finalText
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
if (itemType === "commandExecution") {
|
|
409
|
-
return {
|
|
410
|
-
type: input.phase,
|
|
411
|
-
timestamp: input.timestamp,
|
|
412
|
-
item: {
|
|
413
|
-
id: itemId,
|
|
414
|
-
type: "command_execution",
|
|
415
|
-
command: normalizeString(item.command),
|
|
416
|
-
cwd: normalizeString(item.cwd),
|
|
417
|
-
status: normalizeStatus(item.status),
|
|
418
|
-
aggregated_output: normalizeString(item.aggregatedOutput),
|
|
419
|
-
exit_code: typeof item.exitCode === "number" ? item.exitCode : null,
|
|
420
|
-
duration_ms: typeof item.durationMs === "number" ? item.durationMs : null
|
|
421
|
-
}
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
if (itemType === "mcpToolCall") {
|
|
425
|
-
return {
|
|
426
|
-
type: input.phase,
|
|
427
|
-
timestamp: input.timestamp,
|
|
428
|
-
item: {
|
|
429
|
-
id: itemId,
|
|
430
|
-
type: "mcp_tool_call",
|
|
431
|
-
server: normalizeString(item.server),
|
|
432
|
-
tool: normalizeString(item.tool),
|
|
433
|
-
status: normalizeStatus(item.status),
|
|
434
|
-
arguments: item.arguments ?? null,
|
|
435
|
-
result: asRecord(item.result) ?? null,
|
|
436
|
-
error: asRecord(item.error) ?? null
|
|
437
|
-
}
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
if (itemType === "dynamicToolCall") {
|
|
441
|
-
const cached = input.dynamicToolResults.get(itemId) ?? null;
|
|
442
|
-
if (input.phase === "item.completed") {
|
|
443
|
-
input.dynamicToolResults.delete(itemId);
|
|
444
|
-
}
|
|
445
|
-
return {
|
|
446
|
-
type: input.phase,
|
|
447
|
-
timestamp: input.timestamp,
|
|
448
|
-
item: {
|
|
449
|
-
id: itemId,
|
|
450
|
-
type: "mcp_tool_call",
|
|
451
|
-
server: RIG_DYNAMIC_TOOL_SERVER,
|
|
452
|
-
tool: normalizeString(item.tool),
|
|
453
|
-
status: cached?.isError ? "failed" : normalizeStatus(item.status),
|
|
454
|
-
arguments: item.arguments ?? null,
|
|
455
|
-
result: cached?.structuredResult ?? {
|
|
456
|
-
content_items: item.contentItems ?? null,
|
|
457
|
-
success: item.success ?? null
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
};
|
|
461
|
-
}
|
|
462
|
-
return null;
|
|
463
|
-
}
|
|
464
|
-
function invocationToContentItems(invocation) {
|
|
465
|
-
const items = Array.isArray(invocation.content) ? invocation.content : [];
|
|
466
|
-
const mapped = items.map((item) => {
|
|
467
|
-
const entry = asRecord(item);
|
|
468
|
-
if (!entry || entry.type !== "text" || typeof entry.text !== "string") {
|
|
469
|
-
return null;
|
|
470
|
-
}
|
|
471
|
-
return {
|
|
472
|
-
type: "inputText",
|
|
473
|
-
text: entry.text
|
|
474
|
-
};
|
|
475
|
-
}).filter((item) => Boolean(item));
|
|
476
|
-
return mapped.length > 0 ? mapped : [{ type: "inputText", text: "(empty tool response)" }];
|
|
477
|
-
}
|
|
478
|
-
function emitSyntheticCodexRecord(record) {
|
|
479
|
-
process.stdout.write(`${JSON.stringify(record)}
|
|
480
|
-
`);
|
|
481
|
-
}
|
|
482
|
-
function sanitizeEnv(env) {
|
|
483
|
-
const next = {};
|
|
484
|
-
for (const [key, value] of Object.entries(env)) {
|
|
485
|
-
if (typeof value === "string") {
|
|
486
|
-
next[key] = value;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
return next;
|
|
490
|
-
}
|
|
491
|
-
function writeChildLine(child, line) {
|
|
492
|
-
return new Promise((resolve, reject) => {
|
|
493
|
-
child.stdin.write(line, (error) => {
|
|
494
|
-
if (error) {
|
|
495
|
-
reject(error);
|
|
496
|
-
return;
|
|
497
|
-
}
|
|
498
|
-
resolve();
|
|
499
|
-
});
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
function terminateChild(child) {
|
|
503
|
-
if (child.killed) {
|
|
504
|
-
return;
|
|
505
|
-
}
|
|
506
|
-
try {
|
|
507
|
-
child.kill("SIGTERM");
|
|
508
|
-
} catch {}
|
|
509
|
-
}
|
|
510
|
-
function asRecord(value) {
|
|
511
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
512
|
-
}
|
|
513
|
-
function normalizeString(value) {
|
|
514
|
-
if (typeof value !== "string") {
|
|
515
|
-
return null;
|
|
516
|
-
}
|
|
517
|
-
const trimmed = value.trim();
|
|
518
|
-
return trimmed.length > 0 ? trimmed : null;
|
|
519
|
-
}
|
|
520
|
-
function normalizeStatus(value) {
|
|
521
|
-
const raw = normalizeString(value);
|
|
522
|
-
if (!raw) {
|
|
523
|
-
return null;
|
|
524
|
-
}
|
|
525
|
-
switch (raw) {
|
|
526
|
-
case "inProgress":
|
|
527
|
-
return "in_progress";
|
|
528
|
-
case "completed":
|
|
529
|
-
case "failed":
|
|
530
|
-
case "declined":
|
|
531
|
-
return raw;
|
|
532
|
-
default:
|
|
533
|
-
return raw;
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
function formatJsonRpcError(error) {
|
|
537
|
-
if (!error) {
|
|
538
|
-
return "Unknown app-server error";
|
|
539
|
-
}
|
|
540
|
-
const parts = [error.message, error.data ? JSON.stringify(error.data) : null].filter(Boolean);
|
|
541
|
-
return parts.join(" ");
|
|
542
|
-
}
|
|
543
|
-
export {
|
|
544
|
-
runCodexAppServerTaskRun,
|
|
545
|
-
parseCodexAppServerTaskRunArgs,
|
|
546
|
-
buildCodexAppServerArgs,
|
|
547
|
-
CODEX_APP_SERVER_TASK_RUN_SENTINEL
|
|
548
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { EngineRunLog } from "@rig/contracts";
|
|
2
|
-
type CodexStreamStatus = EngineRunLog["status"];
|
|
3
|
-
export type PendingCodexToolUse = {
|
|
4
|
-
id: string;
|
|
5
|
-
itemType: "command_execution" | "mcp_tool_call";
|
|
6
|
-
name: string | null;
|
|
7
|
-
input: unknown;
|
|
8
|
-
timestamp: string;
|
|
9
|
-
record: Record<string, unknown>;
|
|
10
|
-
};
|
|
11
|
-
type BuildCodexLogsFromRecordInput = {
|
|
12
|
-
runId: string;
|
|
13
|
-
record: Record<string, unknown>;
|
|
14
|
-
createdAtFallback: string;
|
|
15
|
-
status: CodexStreamStatus;
|
|
16
|
-
pendingToolUses: Map<string, PendingCodexToolUse>;
|
|
17
|
-
includeMessageLogs?: boolean;
|
|
18
|
-
};
|
|
19
|
-
export declare function isCodexExecRecord(record: Record<string, unknown>): boolean;
|
|
20
|
-
export declare function extractCodexAssistantMessageText(record: Record<string, unknown>): string | null;
|
|
21
|
-
export declare function buildCodexLogsFromRecord(input: BuildCodexLogsFromRecordInput): EngineRunLog[];
|
|
22
|
-
export declare function flushPendingCodexToolUseLogs(input: {
|
|
23
|
-
runId: string;
|
|
24
|
-
status: CodexStreamStatus;
|
|
25
|
-
pendingToolUses: Map<string, PendingCodexToolUse>;
|
|
26
|
-
}): EngineRunLog[];
|
|
27
|
-
export {};
|