@zonease/happy 0.6.38 → 0.6.39
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/{types-BWpRU1VN.mjs → api-CIZKyfSn.mjs} +136 -1725
- package/dist/{types-DvTsFaqR.cjs → api-CwOCQeLH.cjs} +317 -1961
- package/dist/auth-0VnlXT9f.mjs +181 -0
- package/dist/auth-BE8dD20T.mjs +270 -0
- package/dist/auth-BIleVCw0.cjs +274 -0
- package/dist/auth-Cas9DR3b.cjs +183 -0
- package/dist/browser-Cc08m7of.cjs +22 -0
- package/dist/browser-Dll5hxOV.mjs +20 -0
- package/dist/claudeLocal-CPT3zcIU.mjs +344 -0
- package/dist/claudeLocal-WkgLbl1a.cjs +352 -0
- package/dist/codex/happyMcpStdioBridge.cjs +4 -1
- package/dist/codex/happyMcpStdioBridge.mjs +4 -1
- package/dist/common-BdNgghUJ.mjs +75 -0
- package/dist/common-CZvSRU4p.cjs +83 -0
- package/dist/{config-0Xnc8ARM.cjs → config-Draa-5XC.cjs} +21 -34
- package/dist/{config-_GW4YBCP.mjs → config-rTT4qTU5.mjs} +7 -20
- package/dist/connect-BfC1tYP_.mjs +679 -0
- package/dist/connect-CJZ73syK.cjs +681 -0
- package/dist/{constants-B4x1K7by.cjs → constants-E_UWYTo3.cjs} +2 -2
- package/dist/{constants-BO9OAFOT.mjs → constants-pmXZGibX.mjs} +1 -1
- package/dist/controlClient-CM_QcJnB.mjs +159 -0
- package/dist/controlClient-DZMIsKsT.cjs +168 -0
- package/dist/deviceExec-CU1R9CRb.cjs +84 -0
- package/dist/deviceExec-D93AOVV4.mjs +81 -0
- package/dist/diagnose-B3D1a_v0.cjs +60 -0
- package/dist/diagnose-CuRKXxt1.mjs +58 -0
- package/dist/doctor-C08m5Z9f.cjs +78 -0
- package/dist/doctor-Cya9YSA0.cjs +214 -0
- package/dist/doctor-DZYB6IVc.mjs +211 -0
- package/dist/doctor-ON7pN5G5.mjs +74 -0
- package/dist/downloadImage-DfSFLb-h.mjs +887 -0
- package/dist/downloadImage-MQMrUUxS.cjs +897 -0
- package/dist/enroll-BxlbVftP.cjs +115 -0
- package/dist/enroll-C52x8oly.mjs +113 -0
- package/dist/evidence-Ccd9iYcj.mjs +127 -0
- package/dist/evidence-CjWBG5rX.cjs +129 -0
- package/dist/formatImageMessage-B4lSxlk2.mjs +43 -0
- package/dist/formatImageMessage-DbyG8c2j.cjs +46 -0
- package/dist/github-DKcyF1zp.mjs +57 -0
- package/dist/github-h9GhJJ_C.cjs +59 -0
- package/dist/index-CDTNgfUf.cjs +578 -0
- package/dist/index-CPKdvi7J.mjs +554 -0
- package/dist/index.cjs +812 -40
- package/dist/index.mjs +813 -40
- package/dist/install-BokHRgFW.cjs +98 -0
- package/dist/install-C_cp8b2-.cjs +96 -0
- package/dist/install-DAeCn8ae.mjs +94 -0
- package/dist/install-oRAjVLjP.mjs +95 -0
- package/dist/lib.cjs +18 -12
- package/dist/lib.mjs +13 -7
- package/dist/{loadableToolOutput-va3RLplh.mjs → loadableToolOutput-Cuygmd4K.mjs} +4 -2
- package/dist/{loadableToolOutput-5vdQB98M.cjs → loadableToolOutput-DDCJjywt.cjs} +63 -61
- package/dist/mcpToolSchemas-CjeTfrAs.mjs +62 -0
- package/dist/mcpToolSchemas-DK42yoZ_.cjs +64 -0
- package/dist/persistence-BFjvtUad.mjs +944 -0
- package/dist/persistence-JLUn_Nou.cjs +996 -0
- package/dist/projectPath-BTBIMB57.mjs +10 -0
- package/dist/projectPath-ChLhdOyt.cjs +13 -0
- package/dist/prompt-BTWDZZO0.cjs +25 -0
- package/dist/prompt-BsAZsPbo.mjs +22 -0
- package/dist/release-BMEzNONE.mjs +168 -0
- package/dist/release-EhOJeAZe.cjs +171 -0
- package/dist/run-BDn2aE3Q.cjs +2152 -0
- package/dist/run-DBZqN6Kn.mjs +2128 -0
- package/dist/runClaude-DNHvERX0.mjs +3763 -0
- package/dist/runClaude-uaKxPZPm.cjs +3766 -0
- package/dist/{runCodex-skq0j05d.cjs → runCodex-82UrZLme.cjs} +169 -153
- package/dist/{runCodex-DiKzBf9q.mjs → runCodex-C-RTM0wA.mjs} +36 -20
- package/dist/{runGemini-BeqrVq8R.mjs → runGemini-Bm6-4Xm2.mjs} +34 -17
- package/dist/{runGemini-CVp-CEIh.cjs → runGemini-CXMr4Jwb.cjs} +212 -195
- package/dist/{runOneShot-BQNkNW61.cjs → runOneShot-1B6RMYT7.cjs} +31 -55
- package/dist/{runOneShot-ltCpHbBB.mjs → runOneShot-ioARRHrx.mjs} +14 -38
- package/dist/{serve-BECdtivY.cjs → serve-BtdAhkIE.cjs} +35 -58
- package/dist/{serve-BNdoEDVx.mjs → serve-CwibwU6N.mjs} +12 -35
- package/dist/session-2sU4Bu1R.mjs +108 -0
- package/dist/session-D--F87zL.cjs +110 -0
- package/dist/sessionKeyCache-4Tp8pJ3N.cjs +36 -0
- package/dist/sessionKeyCache-D2BwO91C.mjs +33 -0
- package/dist/sessionList-BCSw3qYt.mjs +51 -0
- package/dist/sessionList-ICJsjNtJ.cjs +54 -0
- package/dist/sessionSummary-Bkz52BPh.cjs +393 -0
- package/dist/sessionSummary-lHGBWQSb.mjs +387 -0
- package/dist/spawnHappyCLI-CoORX0YW.mjs +66 -0
- package/dist/spawnHappyCLI-D_V-AAoP.cjs +70 -0
- package/dist/ssh-BTOlhhxi.cjs +333 -0
- package/dist/ssh-DL_AkRAD.mjs +328 -0
- package/dist/systemdScope-BeOtAkhk.mjs +25 -0
- package/dist/systemdScope-DW3-UoKB.cjs +29 -0
- package/dist/task-CQzrHRZe.mjs +165 -0
- package/dist/task-CSpaC9HX.cjs +167 -0
- package/dist/time-Bj2HRkKH.cjs +33 -0
- package/dist/time-DgsBLJA_.mjs +29 -0
- package/dist/trimIdent-4gvk9Wk6.cjs +22 -0
- package/dist/trimIdent-BAjmv_TG.mjs +20 -0
- package/dist/types-BoJh4Qfv.mjs +57 -0
- package/dist/types-DWeB7aqh.cjs +59 -0
- package/dist/uninstall-BiKyRAb1.cjs +77 -0
- package/dist/uninstall-nFMFGUVM.mjs +75 -0
- package/dist/update-BcqRHXf2.mjs +109 -0
- package/dist/update-Dw8pgsAT.cjs +111 -0
- package/dist/workflowCommon-B0d01Y_a.mjs +56 -0
- package/dist/workflowCommon-Bl568-rt.cjs +62 -0
- package/dist/workflowReports-BEWuQesA.cjs +113 -0
- package/dist/workflowReports-Dd8-4-8f.mjs +108 -0
- package/package.json +1 -1
- package/dist/index-BbCDDvoB.cjs +0 -11376
- package/dist/index-vvZXdswy.mjs +0 -11336
- package/dist/mcpToolSchemas-CdPXJQmb.mjs +0 -175
- package/dist/mcpToolSchemas-f-kttjFw.cjs +0 -186
|
@@ -2,51 +2,67 @@
|
|
|
2
2
|
|
|
3
3
|
var ink = require('ink');
|
|
4
4
|
var React = require('react');
|
|
5
|
-
var
|
|
5
|
+
var api = require('./api-CwOCQeLH.cjs');
|
|
6
6
|
var node_child_process = require('node:child_process');
|
|
7
7
|
var node_readline = require('node:readline');
|
|
8
|
-
var
|
|
8
|
+
var logger = require('./persistence-JLUn_Nou.cjs');
|
|
9
|
+
var loadableToolOutput = require('./loadableToolOutput-DDCJjywt.cjs');
|
|
9
10
|
var node_crypto = require('node:crypto');
|
|
10
|
-
var
|
|
11
|
-
var
|
|
11
|
+
var downloadImage = require('./downloadImage-MQMrUUxS.cjs');
|
|
12
|
+
var run = require('./run-BDn2aE3Q.cjs');
|
|
13
|
+
var constants = require('./constants-E_UWYTo3.cjs');
|
|
14
|
+
var controlClient = require('./controlClient-DZMIsKsT.cjs');
|
|
12
15
|
var node_util = require('node:util');
|
|
13
16
|
var promises = require('node:fs/promises');
|
|
14
17
|
var path = require('node:path');
|
|
15
18
|
require('axios');
|
|
16
|
-
require('chalk');
|
|
17
|
-
require('fs');
|
|
18
|
-
require('node:fs');
|
|
19
|
-
require('node:os');
|
|
20
19
|
require('node:events');
|
|
21
20
|
require('socket.io-client');
|
|
22
21
|
require('zod');
|
|
22
|
+
require('./index-CDTNgfUf.cjs');
|
|
23
23
|
require('@paralleldrive/cuid2');
|
|
24
|
-
require('
|
|
24
|
+
require('./time-Bj2HRkKH.cjs');
|
|
25
|
+
require('node:fs');
|
|
26
|
+
require('node:os');
|
|
25
27
|
require('child_process');
|
|
26
28
|
require('util');
|
|
27
29
|
require('fs/promises');
|
|
28
30
|
require('path');
|
|
31
|
+
require('./projectPath-ChLhdOyt.cjs');
|
|
29
32
|
require('url');
|
|
30
33
|
require('node:module');
|
|
31
34
|
require('ws');
|
|
32
35
|
require('crypto');
|
|
36
|
+
require('tweetnacl');
|
|
33
37
|
require('@stablelib/base64');
|
|
34
38
|
require('expo-server-sdk');
|
|
35
|
-
require('./
|
|
36
|
-
require('
|
|
37
|
-
require('
|
|
38
|
-
require('cross-spawn');
|
|
39
|
-
require('os');
|
|
40
|
-
require('tmp');
|
|
41
|
-
require('qrcode-terminal');
|
|
42
|
-
require('open');
|
|
43
|
-
require('fastify');
|
|
44
|
-
require('fastify-type-provider-zod');
|
|
39
|
+
require('./sessionKeyCache-4Tp8pJ3N.cjs');
|
|
40
|
+
require('chalk');
|
|
41
|
+
require('fs');
|
|
45
42
|
require('@modelcontextprotocol/sdk/server/mcp.js');
|
|
46
43
|
require('node:http');
|
|
47
44
|
require('@modelcontextprotocol/sdk/server/streamableHttp.js');
|
|
48
45
|
require('@modelcontextprotocol/sdk/types.js');
|
|
49
|
-
require('
|
|
46
|
+
require('./deviceExec-CU1R9CRb.cjs');
|
|
47
|
+
require('./auth-BIleVCw0.cjs');
|
|
48
|
+
require('qrcode-terminal');
|
|
49
|
+
require('./browser-Cc08m7of.cjs');
|
|
50
|
+
require('open');
|
|
51
|
+
require('./prompt-BTWDZZO0.cjs');
|
|
52
|
+
require('./trimIdent-4gvk9Wk6.cjs');
|
|
53
|
+
require('./common-CZvSRU4p.cjs');
|
|
54
|
+
require('./mcpToolSchemas-DK42yoZ_.cjs');
|
|
55
|
+
require('./types-DWeB7aqh.cjs');
|
|
56
|
+
require('os');
|
|
57
|
+
require('tmp');
|
|
58
|
+
require('./doctor-Cya9YSA0.cjs');
|
|
59
|
+
require('./doctor-C08m5Z9f.cjs');
|
|
60
|
+
require('ps-list');
|
|
61
|
+
require('cross-spawn');
|
|
62
|
+
require('./spawnHappyCLI-D_V-AAoP.cjs');
|
|
63
|
+
require('./install-BokHRgFW.cjs');
|
|
64
|
+
require('fastify');
|
|
65
|
+
require('fastify-type-provider-zod');
|
|
50
66
|
|
|
51
67
|
class CodexJsonRpcPeer {
|
|
52
68
|
process = null;
|
|
@@ -74,7 +90,7 @@ class CodexJsonRpcPeer {
|
|
|
74
90
|
NODE_NO_WARNINGS: "1",
|
|
75
91
|
NO_COLOR: "1"
|
|
76
92
|
};
|
|
77
|
-
|
|
93
|
+
logger.logger.debug(`[CodexRPC] Spawning: ${command} ${args.join(" ")} in ${opts.cwd}`);
|
|
78
94
|
this.process = node_child_process.spawn(command, args, {
|
|
79
95
|
cwd: opts.cwd,
|
|
80
96
|
stdio: ["pipe", "pipe", "pipe"],
|
|
@@ -86,19 +102,19 @@ class CodexJsonRpcPeer {
|
|
|
86
102
|
this.exitPromise = new Promise((resolve) => {
|
|
87
103
|
this.process.on("close", (code) => {
|
|
88
104
|
this.exited = true;
|
|
89
|
-
|
|
105
|
+
logger.logger.debug(`[CodexRPC] Process exited with code ${code}`);
|
|
90
106
|
resolve(code);
|
|
91
107
|
});
|
|
92
108
|
});
|
|
93
109
|
this.process.on("error", (err) => {
|
|
94
|
-
|
|
110
|
+
logger.logger.warn(`[CodexRPC] Process error: ${err.message}`);
|
|
95
111
|
this.rejectAllPending(new Error(`Codex process error: ${err.message}`));
|
|
96
112
|
});
|
|
97
113
|
if (this.process.stderr) {
|
|
98
114
|
this.process.stderr.on("data", (chunk) => {
|
|
99
115
|
const text = chunk.toString().trim();
|
|
100
116
|
if (text) {
|
|
101
|
-
|
|
117
|
+
logger.logger.debug(`[CodexRPC] stderr: ${text}`);
|
|
102
118
|
}
|
|
103
119
|
});
|
|
104
120
|
}
|
|
@@ -113,7 +129,7 @@ class CodexJsonRpcPeer {
|
|
|
113
129
|
this.handleLine(line);
|
|
114
130
|
});
|
|
115
131
|
this.readline.on("close", () => {
|
|
116
|
-
|
|
132
|
+
logger.logger.debug("[CodexRPC] stdout closed");
|
|
117
133
|
this.rejectAllPending(new Error("Codex process stdout closed"));
|
|
118
134
|
this.closeHandler?.();
|
|
119
135
|
});
|
|
@@ -149,7 +165,7 @@ class CodexJsonRpcPeer {
|
|
|
149
165
|
*/
|
|
150
166
|
notify(method, params) {
|
|
151
167
|
if (this.closed || !this.process?.stdin?.writable) {
|
|
152
|
-
|
|
168
|
+
logger.logger.debug(`[CodexRPC] Cannot send notification '${method}' - peer is closed`);
|
|
153
169
|
return;
|
|
154
170
|
}
|
|
155
171
|
const msg = { method };
|
|
@@ -163,7 +179,7 @@ class CodexJsonRpcPeer {
|
|
|
163
179
|
*/
|
|
164
180
|
respond(id, result) {
|
|
165
181
|
if (this.closed || !this.process?.stdin?.writable) {
|
|
166
|
-
|
|
182
|
+
logger.logger.debug(`[CodexRPC] Cannot respond to request ${id} - peer is closed`);
|
|
167
183
|
return;
|
|
168
184
|
}
|
|
169
185
|
this.writeLine(JSON.stringify({ id, result }));
|
|
@@ -173,7 +189,7 @@ class CodexJsonRpcPeer {
|
|
|
173
189
|
*/
|
|
174
190
|
respondError(id, error) {
|
|
175
191
|
if (this.closed || !this.process?.stdin?.writable) {
|
|
176
|
-
|
|
192
|
+
logger.logger.debug(`[CodexRPC] Cannot respond error to request ${id} - peer is closed`);
|
|
177
193
|
return;
|
|
178
194
|
}
|
|
179
195
|
this.writeLine(JSON.stringify({ id, error }));
|
|
@@ -216,7 +232,7 @@ class CodexJsonRpcPeer {
|
|
|
216
232
|
new Promise((resolve) => setTimeout(() => resolve(false), 3e3))
|
|
217
233
|
]);
|
|
218
234
|
if (!didExit) {
|
|
219
|
-
|
|
235
|
+
logger.logger.debug("[CodexRPC] Process group did not exit after SIGTERM, sending SIGKILL");
|
|
220
236
|
const killResult = this.killProcessGroup(child, pid, "SIGKILL");
|
|
221
237
|
if (killResult !== "dead") {
|
|
222
238
|
await Promise.race([
|
|
@@ -233,7 +249,7 @@ class CodexJsonRpcPeer {
|
|
|
233
249
|
]);
|
|
234
250
|
}
|
|
235
251
|
if (!this.exited) {
|
|
236
|
-
|
|
252
|
+
logger.logger.warn(`[CodexRPC] Process ${pid} did not confirm exit \u2014 may have leaked`);
|
|
237
253
|
}
|
|
238
254
|
}
|
|
239
255
|
this.process = null;
|
|
@@ -256,7 +272,7 @@ class CodexJsonRpcPeer {
|
|
|
256
272
|
this.process?.stdin?.write(json + "\n");
|
|
257
273
|
} catch (err) {
|
|
258
274
|
if (err.code !== "EPIPE") {
|
|
259
|
-
|
|
275
|
+
logger.logger.debug(`[CodexRPC] Write error:`, err);
|
|
260
276
|
}
|
|
261
277
|
}
|
|
262
278
|
}
|
|
@@ -267,7 +283,7 @@ class CodexJsonRpcPeer {
|
|
|
267
283
|
try {
|
|
268
284
|
msg = JSON.parse(trimmed);
|
|
269
285
|
} catch {
|
|
270
|
-
|
|
286
|
+
logger.logger.debug(`[CodexRPC] Non-JSON stdout: ${trimmed.slice(0, 200)}`);
|
|
271
287
|
return;
|
|
272
288
|
}
|
|
273
289
|
if (typeof msg !== "object" || msg === null) return;
|
|
@@ -282,14 +298,14 @@ class CodexJsonRpcPeer {
|
|
|
282
298
|
} else if (hasMethod && !hasId) {
|
|
283
299
|
this.handleNotification(msg);
|
|
284
300
|
} else {
|
|
285
|
-
|
|
301
|
+
logger.logger.debug(`[CodexRPC] Unrecognized message shape:`, msg);
|
|
286
302
|
}
|
|
287
303
|
}
|
|
288
304
|
handleResponse(msg) {
|
|
289
305
|
const id = msg.id;
|
|
290
306
|
const pending = this.pendingRequests.get(id);
|
|
291
307
|
if (!pending) {
|
|
292
|
-
|
|
308
|
+
logger.logger.debug(`[CodexRPC] Received response for unknown request id=${id}`);
|
|
293
309
|
return;
|
|
294
310
|
}
|
|
295
311
|
this.pendingRequests.delete(id);
|
|
@@ -308,7 +324,7 @@ class CodexJsonRpcPeer {
|
|
|
308
324
|
if (this.serverRequestHandler) {
|
|
309
325
|
this.serverRequestHandler(method, params, id);
|
|
310
326
|
} else {
|
|
311
|
-
|
|
327
|
+
logger.logger.debug(`[CodexRPC] No handler for server request '${method}', responding with null`);
|
|
312
328
|
this.respond(id, null);
|
|
313
329
|
}
|
|
314
330
|
}
|
|
@@ -318,7 +334,7 @@ class CodexJsonRpcPeer {
|
|
|
318
334
|
if (this.notificationHandler) {
|
|
319
335
|
this.notificationHandler(method, params);
|
|
320
336
|
} else {
|
|
321
|
-
|
|
337
|
+
logger.logger.debug(`[CodexRPC] No handler for notification '${method}'`);
|
|
322
338
|
}
|
|
323
339
|
}
|
|
324
340
|
/**
|
|
@@ -339,7 +355,7 @@ class CodexJsonRpcPeer {
|
|
|
339
355
|
if (code === "ESRCH") {
|
|
340
356
|
return "dead";
|
|
341
357
|
}
|
|
342
|
-
|
|
358
|
+
logger.logger.warn(`[CodexRPC] process.kill(-${pid}, ${signal}) failed: ${code}, falling back to direct kill`);
|
|
343
359
|
try {
|
|
344
360
|
child.kill(signal);
|
|
345
361
|
} catch {
|
|
@@ -362,7 +378,7 @@ class CodexJsonRpcPeer {
|
|
|
362
378
|
if (status === 128) {
|
|
363
379
|
return "dead";
|
|
364
380
|
}
|
|
365
|
-
|
|
381
|
+
logger.logger.warn(`[CodexRPC] taskkill failed for PID ${pid} (exit ${status}): ${err instanceof Error ? err.message : err}`);
|
|
366
382
|
return "failed";
|
|
367
383
|
}
|
|
368
384
|
}
|
|
@@ -522,7 +538,7 @@ class CodexAppServerBackend {
|
|
|
522
538
|
this.buildThreadParams()
|
|
523
539
|
);
|
|
524
540
|
threadId = newResult.thread.id;
|
|
525
|
-
|
|
541
|
+
logger.logger.info(`[CodexBackend] New thread: id=${threadId}, model=${newResult.model}`);
|
|
526
542
|
this.handleSessionConfigured({
|
|
527
543
|
sessionId: threadId,
|
|
528
544
|
model: newResult.model,
|
|
@@ -553,7 +569,7 @@ class CodexAppServerBackend {
|
|
|
553
569
|
turnId: this.currentTurnId ?? ""
|
|
554
570
|
}, 5e3);
|
|
555
571
|
} catch {
|
|
556
|
-
|
|
572
|
+
logger.logger.debug("[CodexBackend] Interrupt failed (process may have already exited)");
|
|
557
573
|
}
|
|
558
574
|
}
|
|
559
575
|
onMessage(handler) {
|
|
@@ -566,7 +582,7 @@ class CodexAppServerBackend {
|
|
|
566
582
|
async respondToPermission(requestId, approved) {
|
|
567
583
|
const pending = this.pendingApprovals.get(requestId);
|
|
568
584
|
if (!pending) {
|
|
569
|
-
|
|
585
|
+
logger.logger.debug(`[CodexBackend] No pending approval for requestId=${requestId}`);
|
|
570
586
|
return;
|
|
571
587
|
}
|
|
572
588
|
this.pendingApprovals.delete(requestId);
|
|
@@ -703,7 +719,7 @@ class CodexAppServerBackend {
|
|
|
703
719
|
try {
|
|
704
720
|
handler(msg);
|
|
705
721
|
} catch (err) {
|
|
706
|
-
|
|
722
|
+
logger.logger.debug(`[CodexBackend] Message handler error: ${err}`);
|
|
707
723
|
}
|
|
708
724
|
}
|
|
709
725
|
}
|
|
@@ -782,16 +798,16 @@ class CodexAppServerBackend {
|
|
|
782
798
|
// ── Deprecation & config warnings ──
|
|
783
799
|
case Methods.NOTIFY_DEPRECATION:
|
|
784
800
|
case Methods.NOTIFY_CONFIG_WARNING:
|
|
785
|
-
|
|
801
|
+
logger.logger.debug(`[CodexBackend] ${method}: ${JSON.stringify(p)}`);
|
|
786
802
|
break;
|
|
787
803
|
default:
|
|
788
|
-
|
|
804
|
+
logger.logger.debug(`[CodexBackend] Unhandled notification: ${method}`);
|
|
789
805
|
break;
|
|
790
806
|
}
|
|
791
807
|
}
|
|
792
808
|
handleSessionConfigured(params) {
|
|
793
809
|
this.sessionId = params.sessionId;
|
|
794
|
-
|
|
810
|
+
logger.logger.debug(`[CodexBackend] Session configured: model=${params.model}, sessionId=${params.sessionId}`);
|
|
795
811
|
this.emit({
|
|
796
812
|
type: "event",
|
|
797
813
|
name: "session_configured",
|
|
@@ -859,7 +875,7 @@ class CodexAppServerBackend {
|
|
|
859
875
|
case "contextCompaction":
|
|
860
876
|
break;
|
|
861
877
|
default:
|
|
862
|
-
|
|
878
|
+
logger.logger.debug(`[CodexBackend] Unhandled item/started type: ${item.type}`);
|
|
863
879
|
break;
|
|
864
880
|
}
|
|
865
881
|
}
|
|
@@ -921,7 +937,7 @@ class CodexAppServerBackend {
|
|
|
921
937
|
case "imageGeneration":
|
|
922
938
|
break;
|
|
923
939
|
default:
|
|
924
|
-
|
|
940
|
+
logger.logger.debug(`[CodexBackend] Unhandled item/completed type: ${item.type}`);
|
|
925
941
|
break;
|
|
926
942
|
}
|
|
927
943
|
}
|
|
@@ -997,7 +1013,7 @@ class CodexAppServerBackend {
|
|
|
997
1013
|
this.peer.respond(id, { success: false, contentItems: [] });
|
|
998
1014
|
break;
|
|
999
1015
|
default:
|
|
1000
|
-
|
|
1016
|
+
logger.logger.debug(`[CodexBackend] Unhandled server request: ${method}`);
|
|
1001
1017
|
this.peer.respond(id, null);
|
|
1002
1018
|
break;
|
|
1003
1019
|
}
|
|
@@ -1007,7 +1023,7 @@ class CodexAppServerBackend {
|
|
|
1007
1023
|
const rawParams = params;
|
|
1008
1024
|
const callId = this.getApprovalCallId(rawParams);
|
|
1009
1025
|
if (!callId) {
|
|
1010
|
-
|
|
1026
|
+
logger.logger.warn("[CodexBackend] applyPatchApproval missing callId/call_id; denying request");
|
|
1011
1027
|
this.peer.respond(jsonRpcId, { decision: "denied" });
|
|
1012
1028
|
return;
|
|
1013
1029
|
}
|
|
@@ -1041,7 +1057,7 @@ class CodexAppServerBackend {
|
|
|
1041
1057
|
const rawParams = params;
|
|
1042
1058
|
const callId = this.getApprovalCallId(rawParams);
|
|
1043
1059
|
if (!callId) {
|
|
1044
|
-
|
|
1060
|
+
logger.logger.warn("[CodexBackend] execCommandApproval missing callId/call_id; denying request");
|
|
1045
1061
|
this.peer.respond(jsonRpcId, { decision: "denied" });
|
|
1046
1062
|
return;
|
|
1047
1063
|
}
|
|
@@ -1133,7 +1149,7 @@ class CodexAppServerBackend {
|
|
|
1133
1149
|
const fullToolName = parsed.serverName && parsed.toolTitle ? buildMcpToolName(parsed.serverName, parsed.toolTitle) : parsed.toolTitle || parsed.serverName || "mcp_tool_call";
|
|
1134
1150
|
const callId = `mcp-elicit-${String(jsonRpcId)}`;
|
|
1135
1151
|
this.options.permissionHandler.handleToolCall(callId, fullToolName, parsed.toolParams).then((result) => {
|
|
1136
|
-
|
|
1152
|
+
logger.logger.debug("[CodexBackend] MCP elicitation decision", { callId, decision: result.decision });
|
|
1137
1153
|
if (result.decision !== "approved" && result.decision !== "approved_for_session") {
|
|
1138
1154
|
this.peer.respond(jsonRpcId, { action: "decline" });
|
|
1139
1155
|
return;
|
|
@@ -1141,7 +1157,7 @@ class CodexAppServerBackend {
|
|
|
1141
1157
|
const response = result.decision === "approved_for_session" ? { action: "accept", meta: { persist: "session" } } : { action: "accept" };
|
|
1142
1158
|
this.peer.respond(jsonRpcId, response);
|
|
1143
1159
|
}).catch((err) => {
|
|
1144
|
-
|
|
1160
|
+
logger.logger.warn("[CodexBackend] MCP elicitation permission handler rejected", err);
|
|
1145
1161
|
this.peer.respond(jsonRpcId, { action: "decline" });
|
|
1146
1162
|
});
|
|
1147
1163
|
}
|
|
@@ -1292,7 +1308,7 @@ function createCodexBackend(options) {
|
|
|
1292
1308
|
resumeFile: options.resumeFile,
|
|
1293
1309
|
signal: options.signal
|
|
1294
1310
|
};
|
|
1295
|
-
|
|
1311
|
+
logger.logger.debug("[Codex] Creating app-server backend with options:", {
|
|
1296
1312
|
cwd: backendOptions.cwd,
|
|
1297
1313
|
model: model ?? "(Codex CLI default)",
|
|
1298
1314
|
reasoningEffort: options.reasoningEffort ?? "(Codex CLI default)",
|
|
@@ -1320,7 +1336,7 @@ class CodexPermissionHandler extends loadableToolOutput.BasePermissionHandler {
|
|
|
1320
1336
|
}
|
|
1321
1337
|
setPermissionMode(mode) {
|
|
1322
1338
|
this.currentPermissionMode = mode;
|
|
1323
|
-
|
|
1339
|
+
logger.logger.debug(`${this.getLogPrefix()} Permission mode set to: ${mode}`);
|
|
1324
1340
|
}
|
|
1325
1341
|
shouldAutoApprove(toolName, toolCallId) {
|
|
1326
1342
|
const alwaysAutoApproveNames = ["change_title", "happy__change_title", "preview_html", "happy__preview_html", "CodexReasoning", "think", "save_memory"];
|
|
@@ -1354,7 +1370,7 @@ class CodexPermissionHandler extends loadableToolOutput.BasePermissionHandler {
|
|
|
1354
1370
|
*/
|
|
1355
1371
|
async handleToolCall(toolCallId, toolName, input) {
|
|
1356
1372
|
if (this.shouldAutoApprove(toolName, toolCallId)) {
|
|
1357
|
-
|
|
1373
|
+
logger.logger.debug(`${this.getLogPrefix()} Auto-approving tool ${toolName} (${toolCallId}) in ${this.currentPermissionMode} mode`);
|
|
1358
1374
|
this.session.updateAgentState((currentState) => ({
|
|
1359
1375
|
...currentState,
|
|
1360
1376
|
completedRequests: {
|
|
@@ -1381,7 +1397,7 @@ class CodexPermissionHandler extends loadableToolOutput.BasePermissionHandler {
|
|
|
1381
1397
|
input
|
|
1382
1398
|
});
|
|
1383
1399
|
this.addPendingRequestToState(toolCallId, toolName, input);
|
|
1384
|
-
|
|
1400
|
+
logger.logger.debug(`${this.getLogPrefix()} Permission request sent for tool: ${toolName} (${toolCallId}) in ${this.currentPermissionMode} mode`);
|
|
1385
1401
|
});
|
|
1386
1402
|
}
|
|
1387
1403
|
}
|
|
@@ -1489,7 +1505,7 @@ class DiffProcessor {
|
|
|
1489
1505
|
this.rebuildPerFileMap(perFile);
|
|
1490
1506
|
return;
|
|
1491
1507
|
}
|
|
1492
|
-
|
|
1508
|
+
logger.logger.debug(`[DiffProcessor] ${changedFiles.length} file(s) changed, sending CodexDiff tool call`);
|
|
1493
1509
|
const callId = node_crypto.randomUUID();
|
|
1494
1510
|
let totalAdditions = 0;
|
|
1495
1511
|
let totalDeletions = 0;
|
|
@@ -1511,7 +1527,7 @@ class DiffProcessor {
|
|
|
1511
1527
|
deletions: f.deletions,
|
|
1512
1528
|
timestamp: Date.now()
|
|
1513
1529
|
}));
|
|
1514
|
-
|
|
1530
|
+
api.saveDiffRecords(this.sessionId, records);
|
|
1515
1531
|
}
|
|
1516
1532
|
const toolCall = {
|
|
1517
1533
|
type: "tool-call",
|
|
@@ -1540,7 +1556,7 @@ class DiffProcessor {
|
|
|
1540
1556
|
* Reset the processor state (called on task_complete or turn_aborted)
|
|
1541
1557
|
*/
|
|
1542
1558
|
reset() {
|
|
1543
|
-
|
|
1559
|
+
logger.logger.debug("[DiffProcessor] Resetting diff state");
|
|
1544
1560
|
this.previousPerFile.clear();
|
|
1545
1561
|
}
|
|
1546
1562
|
/**
|
|
@@ -1661,7 +1677,7 @@ const CodexDisplay = ({ messageBuffer, logPath, onExit }) => {
|
|
|
1661
1677
|
alignItems: "center",
|
|
1662
1678
|
flexDirection: "column"
|
|
1663
1679
|
},
|
|
1664
|
-
/* @__PURE__ */ React.createElement(ink.Box, { flexDirection: "column", alignItems: "center" }, actionInProgress ? /* @__PURE__ */ React.createElement(ink.Text, { color: "gray", bold: true }, "Exiting agent...") : confirmationMode ? /* @__PURE__ */ React.createElement(ink.Text, { color: "red", bold: true }, "\u26A0\uFE0F Press Ctrl-C again to exit the agent") : /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(ink.Text, { color: "green", bold: true }, "\u{1F916} Codex Agent Running \u2022 Ctrl-C to exit")),
|
|
1680
|
+
/* @__PURE__ */ React.createElement(ink.Box, { flexDirection: "column", alignItems: "center" }, actionInProgress ? /* @__PURE__ */ React.createElement(ink.Text, { color: "gray", bold: true }, "Exiting agent...") : confirmationMode ? /* @__PURE__ */ React.createElement(ink.Text, { color: "red", bold: true }, "\u26A0\uFE0F Press Ctrl-C again to exit the agent") : /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(ink.Text, { color: "green", bold: true }, "\u{1F916} Codex Agent Running \u2022 Ctrl-C to exit")), logger.isDebug() && logPath && /* @__PURE__ */ React.createElement(ink.Text, { color: "gray", dimColor: true }, "Debug logs: ", logPath))
|
|
1665
1681
|
));
|
|
1666
1682
|
};
|
|
1667
1683
|
|
|
@@ -1702,7 +1718,7 @@ function resolveCodexSessionFile(sessionIdOrPath) {
|
|
|
1702
1718
|
if (path.isAbsolute(sessionIdOrPath)) {
|
|
1703
1719
|
return sessionIdOrPath;
|
|
1704
1720
|
}
|
|
1705
|
-
return
|
|
1721
|
+
return api.findCodexSessionFile(sessionIdOrPath);
|
|
1706
1722
|
}
|
|
1707
1723
|
async function backfillCodexSessionHistory(opts) {
|
|
1708
1724
|
const maxMessages = opts.maxMessages ?? 200;
|
|
@@ -1710,14 +1726,14 @@ async function backfillCodexSessionHistory(opts) {
|
|
|
1710
1726
|
const maxBytes = opts.maxBytes ?? 3 * 1024 * 1024;
|
|
1711
1727
|
const filePath = resolveCodexSessionFile(opts.sessionIdOrPath);
|
|
1712
1728
|
if (!filePath) {
|
|
1713
|
-
|
|
1729
|
+
logger.logger.debug(`[CODEX-BACKFILL] Session file not found for: ${opts.sessionIdOrPath}`);
|
|
1714
1730
|
return;
|
|
1715
1731
|
}
|
|
1716
1732
|
let content;
|
|
1717
1733
|
try {
|
|
1718
1734
|
content = await promises.readFile(filePath, "utf-8");
|
|
1719
1735
|
} catch (error) {
|
|
1720
|
-
|
|
1736
|
+
logger.logger.debug(`[CODEX-BACKFILL] Failed to read file: ${filePath}`, error);
|
|
1721
1737
|
return;
|
|
1722
1738
|
}
|
|
1723
1739
|
const lines = content.split("\n");
|
|
@@ -1735,8 +1751,8 @@ async function backfillCodexSessionHistory(opts) {
|
|
|
1735
1751
|
const payload = parsed.payload;
|
|
1736
1752
|
const timestamp = parsed.timestamp || "";
|
|
1737
1753
|
if (payload?.role === "user") {
|
|
1738
|
-
const text =
|
|
1739
|
-
if (!text ||
|
|
1754
|
+
const text = api.extractUserText(payload);
|
|
1755
|
+
if (!text || api.isSystemMessage(text)) continue;
|
|
1740
1756
|
allMessages.push({
|
|
1741
1757
|
role: "user",
|
|
1742
1758
|
text,
|
|
@@ -1757,7 +1773,7 @@ async function backfillCodexSessionHistory(opts) {
|
|
|
1757
1773
|
}
|
|
1758
1774
|
}
|
|
1759
1775
|
if (allMessages.length === 0) {
|
|
1760
|
-
|
|
1776
|
+
logger.logger.debug("[CODEX-BACKFILL] No messages to backfill");
|
|
1761
1777
|
return;
|
|
1762
1778
|
}
|
|
1763
1779
|
const selected = [];
|
|
@@ -1778,10 +1794,10 @@ async function backfillCodexSessionHistory(opts) {
|
|
|
1778
1794
|
}
|
|
1779
1795
|
selected.reverse();
|
|
1780
1796
|
const fileKey = path.basename(filePath, ".jsonl");
|
|
1781
|
-
|
|
1797
|
+
logger.logger.debug(`[CODEX-BACKFILL] Backfilling ${selected.length} messages (users: ${userCount}, total: ${totalCount}, bytes: ${totalBytes})`);
|
|
1782
1798
|
const batch = selected.map((msg) => ({
|
|
1783
1799
|
content: buildMessageContent(msg),
|
|
1784
|
-
localId: `codex-log:${fileKey}:${
|
|
1800
|
+
localId: `codex-log:${fileKey}:${api.generateStableUuid(msg.timestamp, msg.index)}`
|
|
1785
1801
|
}));
|
|
1786
1802
|
await opts.sendBatch(batch);
|
|
1787
1803
|
}
|
|
@@ -1865,30 +1881,30 @@ function mapSandbox(permissionMode) {
|
|
|
1865
1881
|
}
|
|
1866
1882
|
async function runCodex(opts) {
|
|
1867
1883
|
const sessionTag = node_crypto.randomUUID();
|
|
1868
|
-
|
|
1869
|
-
const api = await
|
|
1870
|
-
|
|
1871
|
-
const settings = await
|
|
1884
|
+
api.connectionState.setBackend("Codex");
|
|
1885
|
+
const api$1 = await api.ApiClient.create(opts.credentials);
|
|
1886
|
+
logger.logger.debug(`[codex] Starting with options: startedBy=${opts.startedBy || "terminal"}`);
|
|
1887
|
+
const settings = await logger.readSettings();
|
|
1872
1888
|
let machineId = settings?.machineId;
|
|
1873
1889
|
if (!machineId) {
|
|
1874
1890
|
console.error(`[START] No machine ID found in settings, which is unexpected since authAndSetupMachineIfNeeded should have created it. Please report this issue on https://github.com/ZonEaseTech/happy-wfs/issues`);
|
|
1875
1891
|
process.exit(1);
|
|
1876
1892
|
}
|
|
1877
|
-
|
|
1878
|
-
await api.getOrCreateMachine({
|
|
1893
|
+
logger.logger.debug(`Using machineId: ${machineId}`);
|
|
1894
|
+
await api$1.getOrCreateMachine({
|
|
1879
1895
|
machineId,
|
|
1880
|
-
metadata:
|
|
1896
|
+
metadata: run.initialMachineMetadata
|
|
1881
1897
|
});
|
|
1882
1898
|
const { state, metadata } = loadableToolOutput.createSessionMetadata({
|
|
1883
1899
|
flavor: "codex",
|
|
1884
1900
|
machineId,
|
|
1885
1901
|
startedBy: opts.startedBy
|
|
1886
1902
|
});
|
|
1887
|
-
const response = await api.getOrCreateSession({ tag: sessionTag, metadata, state });
|
|
1903
|
+
const response = await api$1.getOrCreateSession({ tag: sessionTag, metadata, state });
|
|
1888
1904
|
let session;
|
|
1889
1905
|
let permissionHandler;
|
|
1890
1906
|
const { session: initialSession, reconnectionHandle } = loadableToolOutput.setupOfflineReconnection({
|
|
1891
|
-
api,
|
|
1907
|
+
api: api$1,
|
|
1892
1908
|
sessionTag,
|
|
1893
1909
|
metadata,
|
|
1894
1910
|
state,
|
|
@@ -1911,7 +1927,7 @@ async function runCodex(opts) {
|
|
|
1911
1927
|
}
|
|
1912
1928
|
}));
|
|
1913
1929
|
}
|
|
1914
|
-
const injectedMemories = await api.listMemories();
|
|
1930
|
+
const injectedMemories = await api$1.listMemories();
|
|
1915
1931
|
let initialMemoryAppendPrompt;
|
|
1916
1932
|
if (injectedMemories.length > 0) {
|
|
1917
1933
|
const memoryBlock = "<user_memory>\n" + injectedMemories.map((m) => m.content).join("\n\n") + "\n</user_memory>";
|
|
@@ -1921,22 +1937,22 @@ async function runCodex(opts) {
|
|
|
1921
1937
|
...currentMetadata,
|
|
1922
1938
|
injectedMemoryIds
|
|
1923
1939
|
}));
|
|
1924
|
-
|
|
1940
|
+
logger.logger.debug(`[START] Injected ${injectedMemoryIds.length} memories into Codex session`);
|
|
1925
1941
|
}
|
|
1926
1942
|
if (response) {
|
|
1927
1943
|
try {
|
|
1928
|
-
|
|
1929
|
-
const result = await
|
|
1944
|
+
logger.logger.debug(`[START] Reporting session ${response.id} to daemon`);
|
|
1945
|
+
const result = await controlClient.notifyDaemonSessionStarted(response.id, metadata);
|
|
1930
1946
|
if (result.error) {
|
|
1931
|
-
|
|
1947
|
+
logger.logger.debug(`[START] Failed to report to daemon (may not be running):`, result.error);
|
|
1932
1948
|
} else {
|
|
1933
|
-
|
|
1949
|
+
logger.logger.debug(`[START] Reported session ${response.id} to daemon`);
|
|
1934
1950
|
}
|
|
1935
1951
|
} catch (error) {
|
|
1936
|
-
|
|
1952
|
+
logger.logger.debug("[START] Failed to report to daemon (may not be running):", error);
|
|
1937
1953
|
}
|
|
1938
1954
|
}
|
|
1939
|
-
const messageQueue = new
|
|
1955
|
+
const messageQueue = new downloadImage.MessageQueue2((mode) => downloadImage.hashObject({
|
|
1940
1956
|
permissionMode: mode.permissionMode,
|
|
1941
1957
|
model: mode.model,
|
|
1942
1958
|
reasoningEffort: mode.reasoningEffort
|
|
@@ -1992,24 +2008,24 @@ async function runCodex(opts) {
|
|
|
1992
2008
|
if (message.meta?.permissionMode) {
|
|
1993
2009
|
messagePermissionMode = message.meta.permissionMode;
|
|
1994
2010
|
currentPermissionMode = messagePermissionMode;
|
|
1995
|
-
|
|
2011
|
+
logger.logger.debug(`[Codex] Permission mode updated from user message to: ${currentPermissionMode}`);
|
|
1996
2012
|
} else {
|
|
1997
|
-
|
|
2013
|
+
logger.logger.debug(`[Codex] User message received with no permission mode override, using current: ${currentPermissionMode ?? "default (effective)"}`);
|
|
1998
2014
|
}
|
|
1999
2015
|
let messageModel = currentModel;
|
|
2000
2016
|
if (message.meta?.hasOwnProperty("model")) {
|
|
2001
2017
|
messageModel = message.meta.model || void 0;
|
|
2002
2018
|
currentModel = messageModel;
|
|
2003
|
-
|
|
2019
|
+
logger.logger.debug(`[Codex] Model updated from user message: ${messageModel || "reset to default"}`);
|
|
2004
2020
|
} else {
|
|
2005
|
-
|
|
2021
|
+
logger.logger.debug(`[Codex] User message received with no model override, using current: ${currentModel || "default"}`);
|
|
2006
2022
|
}
|
|
2007
2023
|
let messageReasoningEffort = currentSessionReasoningEffort;
|
|
2008
2024
|
if (message.meta?.hasOwnProperty("reasoningEffort")) {
|
|
2009
2025
|
messageReasoningEffort = message.meta.reasoningEffort || void 0;
|
|
2010
|
-
|
|
2026
|
+
logger.logger.debug(`[Codex] Reasoning effort updated from user message: ${messageReasoningEffort || "reset to default"}`);
|
|
2011
2027
|
} else {
|
|
2012
|
-
|
|
2028
|
+
logger.logger.debug(`[Codex] User message received with no reasoning effort override, using current: ${currentSessionReasoningEffort || "default"}`);
|
|
2013
2029
|
}
|
|
2014
2030
|
syncSessionModelInfo({ model: messageModel, reasoningEffort: messageReasoningEffort });
|
|
2015
2031
|
if (sessionSystemPrompt === void 0) {
|
|
@@ -2023,7 +2039,7 @@ async function runCodex(opts) {
|
|
|
2023
2039
|
const messageText = message.content.text;
|
|
2024
2040
|
const images = isMixedContent && "images" in message.content ? message.content.images : [];
|
|
2025
2041
|
if (images.length > 0) {
|
|
2026
|
-
|
|
2042
|
+
logger.logger.debug(`[Codex] Received mixed message with ${images.length} image(s)`);
|
|
2027
2043
|
}
|
|
2028
2044
|
const enhancedMode = {
|
|
2029
2045
|
permissionMode: messagePermissionMode || "default",
|
|
@@ -2049,13 +2065,13 @@ async function runCodex(opts) {
|
|
|
2049
2065
|
const sendReady = () => {
|
|
2050
2066
|
session.sendSessionEvent({ type: "ready" });
|
|
2051
2067
|
try {
|
|
2052
|
-
api.push().sendToAllDevices(
|
|
2068
|
+
api$1.push().sendToAllDevices(
|
|
2053
2069
|
"It's ready!",
|
|
2054
2070
|
"Codex is waiting for your command",
|
|
2055
2071
|
{ sessionId: session.sessionId }
|
|
2056
2072
|
);
|
|
2057
2073
|
} catch (pushError) {
|
|
2058
|
-
|
|
2074
|
+
logger.logger.debug("[Codex] Failed to send ready push", pushError);
|
|
2059
2075
|
}
|
|
2060
2076
|
session.flush().finally(() => {
|
|
2061
2077
|
session.updateAgentState((state2) => ({
|
|
@@ -2065,14 +2081,14 @@ async function runCodex(opts) {
|
|
|
2065
2081
|
});
|
|
2066
2082
|
};
|
|
2067
2083
|
function logActiveHandles(tag) {
|
|
2068
|
-
if (!
|
|
2084
|
+
if (!logger.isDebug()) return;
|
|
2069
2085
|
const anyProc = process;
|
|
2070
2086
|
const handles = typeof anyProc._getActiveHandles === "function" ? anyProc._getActiveHandles() : [];
|
|
2071
2087
|
const requests = typeof anyProc._getActiveRequests === "function" ? anyProc._getActiveRequests() : [];
|
|
2072
|
-
|
|
2088
|
+
logger.logger.debug(`[codex][handles] ${tag}: handles=${handles.length} requests=${requests.length}`);
|
|
2073
2089
|
try {
|
|
2074
2090
|
const kinds = handles.map((h) => h && h.constructor ? h.constructor.name : typeof h);
|
|
2075
|
-
|
|
2091
|
+
logger.logger.debug(`[codex][handles] kinds=${JSON.stringify(kinds)}`);
|
|
2076
2092
|
} catch {
|
|
2077
2093
|
}
|
|
2078
2094
|
}
|
|
@@ -2083,14 +2099,14 @@ async function runCodex(opts) {
|
|
|
2083
2099
|
const envResumeFile = process.env.HAPPY_CODEX_RESUME_FILE || null;
|
|
2084
2100
|
let backend = null;
|
|
2085
2101
|
async function handleAbort() {
|
|
2086
|
-
|
|
2102
|
+
logger.logger.debug("[Codex] Abort requested - stopping current task");
|
|
2087
2103
|
abortRequested = true;
|
|
2088
2104
|
try {
|
|
2089
2105
|
const b = backend;
|
|
2090
2106
|
if (b?.isAlive) {
|
|
2091
2107
|
const sid = b.getSessionId();
|
|
2092
2108
|
if (sid) storedSessionIdForResume = sid;
|
|
2093
|
-
|
|
2109
|
+
logger.logger.debug("[Codex] Stored session for resume:", storedSessionIdForResume);
|
|
2094
2110
|
if (b.getConversationId()) {
|
|
2095
2111
|
b.cancel(b.getConversationId()).catch(() => {
|
|
2096
2112
|
});
|
|
@@ -2102,20 +2118,20 @@ async function runCodex(opts) {
|
|
|
2102
2118
|
if (backend === b) backend = null;
|
|
2103
2119
|
}
|
|
2104
2120
|
reasoningProcessor.abort();
|
|
2105
|
-
|
|
2121
|
+
logger.logger.debug("[Codex] Abort completed");
|
|
2106
2122
|
} catch (error) {
|
|
2107
|
-
|
|
2123
|
+
logger.logger.debug("[Codex] Error during abort:", error);
|
|
2108
2124
|
}
|
|
2109
2125
|
}
|
|
2110
|
-
const mcp = await
|
|
2126
|
+
const mcp = await downloadImage.createMcpContext(session);
|
|
2111
2127
|
const mcpServers = mcp.configForStdio();
|
|
2112
2128
|
const handleKillSession = async () => {
|
|
2113
2129
|
if (killInProgress) {
|
|
2114
|
-
|
|
2130
|
+
logger.logger.debug("[Codex] Kill session already in progress");
|
|
2115
2131
|
return;
|
|
2116
2132
|
}
|
|
2117
2133
|
killInProgress = true;
|
|
2118
|
-
|
|
2134
|
+
logger.logger.debug("[Codex] Kill session requested - terminating process");
|
|
2119
2135
|
isTerminating = true;
|
|
2120
2136
|
shouldExit = true;
|
|
2121
2137
|
thinking = false;
|
|
@@ -2135,41 +2151,41 @@ async function runCodex(opts) {
|
|
|
2135
2151
|
await session.close();
|
|
2136
2152
|
}
|
|
2137
2153
|
} catch (error) {
|
|
2138
|
-
|
|
2154
|
+
logger.logger.debug("[Codex] Error while ending session during termination", error);
|
|
2139
2155
|
}
|
|
2140
2156
|
try {
|
|
2141
2157
|
await handleAbort();
|
|
2142
|
-
|
|
2158
|
+
logger.logger.debug("[Codex] Abort completed, proceeding with backend disposal");
|
|
2143
2159
|
} catch (error) {
|
|
2144
|
-
|
|
2160
|
+
logger.logger.debug("[Codex] Error during abort in termination flow", error);
|
|
2145
2161
|
}
|
|
2146
2162
|
try {
|
|
2147
2163
|
try {
|
|
2148
2164
|
await backend?.dispose();
|
|
2149
2165
|
} catch (e) {
|
|
2150
|
-
|
|
2166
|
+
logger.logger.debug("[Codex] Error while disposing backend during termination", e);
|
|
2151
2167
|
}
|
|
2152
|
-
|
|
2168
|
+
run.stopCaffeinate();
|
|
2153
2169
|
mcp.stop();
|
|
2154
|
-
|
|
2170
|
+
logger.logger.debug("[Codex] Session termination complete, exiting");
|
|
2155
2171
|
process.exit(0);
|
|
2156
2172
|
} catch (error) {
|
|
2157
|
-
|
|
2173
|
+
logger.logger.debug("[Codex] Error during session termination:", error);
|
|
2158
2174
|
process.exit(1);
|
|
2159
2175
|
}
|
|
2160
2176
|
};
|
|
2161
2177
|
session.rpcHandlerManager.registerHandler("abort", handleAbort);
|
|
2162
|
-
|
|
2163
|
-
const messageBuffer = new
|
|
2178
|
+
downloadImage.registerKillSessionHandler(session.rpcHandlerManager, handleKillSession);
|
|
2179
|
+
const messageBuffer = new downloadImage.MessageBuffer();
|
|
2164
2180
|
const hasTTY = process.stdout.isTTY && process.stdin.isTTY;
|
|
2165
2181
|
let inkInstance = null;
|
|
2166
2182
|
if (hasTTY) {
|
|
2167
2183
|
console.clear();
|
|
2168
2184
|
inkInstance = ink.render(React.createElement(CodexDisplay, {
|
|
2169
2185
|
messageBuffer,
|
|
2170
|
-
logPath:
|
|
2186
|
+
logPath: logger.isDebug() ? logger.logger.getLogPath() : void 0,
|
|
2171
2187
|
onExit: async () => {
|
|
2172
|
-
|
|
2188
|
+
logger.logger.debug("[codex]: Exiting agent via Ctrl-C");
|
|
2173
2189
|
shouldExit = true;
|
|
2174
2190
|
await handleAbort();
|
|
2175
2191
|
}
|
|
@@ -2185,19 +2201,19 @@ async function runCodex(opts) {
|
|
|
2185
2201
|
}
|
|
2186
2202
|
process.stdin.setEncoding("utf8");
|
|
2187
2203
|
}
|
|
2188
|
-
permissionHandler = new CodexPermissionHandler(session, api.push());
|
|
2204
|
+
permissionHandler = new CodexPermissionHandler(session, api$1.push());
|
|
2189
2205
|
const validPermissionModes = ["default", "read-only", "safe-yolo", "yolo"];
|
|
2190
2206
|
session.rpcHandlerManager.registerHandler(
|
|
2191
2207
|
"permission-mode-changed",
|
|
2192
2208
|
async (payload) => {
|
|
2193
2209
|
const mode = payload?.mode;
|
|
2194
2210
|
if (!mode || !validPermissionModes.includes(mode)) {
|
|
2195
|
-
|
|
2211
|
+
logger.logger.debug("[Codex] Invalid permission mode via rpc", { mode });
|
|
2196
2212
|
return false;
|
|
2197
2213
|
}
|
|
2198
2214
|
currentPermissionMode = mode;
|
|
2199
2215
|
permissionHandler.setPermissionMode(mode);
|
|
2200
|
-
|
|
2216
|
+
logger.logger.debug(`[Codex] Permission mode updated via rpc to ${mode}`);
|
|
2201
2217
|
return true;
|
|
2202
2218
|
}
|
|
2203
2219
|
);
|
|
@@ -2213,7 +2229,7 @@ async function runCodex(opts) {
|
|
|
2213
2229
|
diffProcessor.setSessionId(session.sessionId);
|
|
2214
2230
|
function handleAgentMessage(msg) {
|
|
2215
2231
|
if (msg.type !== "model-output" && msg.type !== "terminal-output" && msg.type !== "event") {
|
|
2216
|
-
|
|
2232
|
+
logger.logger.debug(`[Codex] AgentMessage: ${msg.type}`);
|
|
2217
2233
|
}
|
|
2218
2234
|
switch (msg.type) {
|
|
2219
2235
|
case "model-output": {
|
|
@@ -2433,7 +2449,7 @@ async function runCodex(opts) {
|
|
|
2433
2449
|
}
|
|
2434
2450
|
function findCodexResumeFile(sessionId) {
|
|
2435
2451
|
if (!sessionId) return null;
|
|
2436
|
-
return
|
|
2452
|
+
return api.findCodexSessionFile(sessionId);
|
|
2437
2453
|
}
|
|
2438
2454
|
async function createBackend(opts2) {
|
|
2439
2455
|
if (backend?.isAlive) {
|
|
@@ -2471,10 +2487,10 @@ async function runCodex(opts) {
|
|
|
2471
2487
|
}
|
|
2472
2488
|
});
|
|
2473
2489
|
} else {
|
|
2474
|
-
|
|
2490
|
+
logger.logger.debug("[Codex] Backfill skipped: socket not connected");
|
|
2475
2491
|
}
|
|
2476
2492
|
} catch (error) {
|
|
2477
|
-
|
|
2493
|
+
logger.logger.debug("[Codex] Backfill failed:", error);
|
|
2478
2494
|
}
|
|
2479
2495
|
}
|
|
2480
2496
|
try {
|
|
@@ -2490,17 +2506,17 @@ async function runCodex(opts) {
|
|
|
2490
2506
|
const batch = await messageQueue.waitForMessagesAndGetAsString();
|
|
2491
2507
|
if (!batch) {
|
|
2492
2508
|
if (!shouldExit) {
|
|
2493
|
-
|
|
2509
|
+
logger.logger.debug("[codex]: Wait returned null while not exiting; continuing");
|
|
2494
2510
|
continue;
|
|
2495
2511
|
}
|
|
2496
|
-
|
|
2512
|
+
logger.logger.debug(`[codex]: batch=${!!batch}, shouldExit=${shouldExit}`);
|
|
2497
2513
|
break;
|
|
2498
2514
|
}
|
|
2499
2515
|
message = batch;
|
|
2500
2516
|
}
|
|
2501
2517
|
if (!message) break;
|
|
2502
|
-
if (
|
|
2503
|
-
|
|
2518
|
+
if (downloadImage.parseClear(message.message).isClear) {
|
|
2519
|
+
logger.logger.debug("[Codex] /clear command detected - resetting session");
|
|
2504
2520
|
messageBuffer.addMessage("Context was reset", "status");
|
|
2505
2521
|
session.sendSessionEvent({ type: "message", message: "Context was reset" });
|
|
2506
2522
|
if (backend) {
|
|
@@ -2523,18 +2539,18 @@ async function runCodex(opts) {
|
|
|
2523
2539
|
continue;
|
|
2524
2540
|
}
|
|
2525
2541
|
if (wasCreated && currentModeHash && message.hash !== currentModeHash) {
|
|
2526
|
-
|
|
2542
|
+
logger.logger.debug("[Codex] Mode changed \u2013 restarting Codex session");
|
|
2527
2543
|
messageBuffer.addMessage("\u2550".repeat(40), "status");
|
|
2528
2544
|
messageBuffer.addMessage("Starting new Codex session (mode changed)...", "status");
|
|
2529
2545
|
try {
|
|
2530
2546
|
const prevSessionId = backend ? backend.getSessionId() : null;
|
|
2531
2547
|
nextResumeFile = findCodexResumeFile(prevSessionId);
|
|
2532
2548
|
if (nextResumeFile) {
|
|
2533
|
-
|
|
2549
|
+
logger.logger.debug(`[Codex] Found resume file: ${nextResumeFile}`);
|
|
2534
2550
|
messageBuffer.addMessage("Resuming previous context\u2026", "status");
|
|
2535
2551
|
}
|
|
2536
2552
|
} catch (e) {
|
|
2537
|
-
|
|
2553
|
+
logger.logger.debug("[Codex] Error searching resume file", e);
|
|
2538
2554
|
}
|
|
2539
2555
|
if (backend) {
|
|
2540
2556
|
try {
|
|
@@ -2562,10 +2578,10 @@ async function runCodex(opts) {
|
|
|
2562
2578
|
const sandbox = mapSandbox(message.mode.permissionMode);
|
|
2563
2579
|
let promptOptions;
|
|
2564
2580
|
if (message.mode.images?.length) {
|
|
2565
|
-
|
|
2581
|
+
logger.logger.debug(`[Codex] Downloading ${message.mode.images.length} image(s)...`);
|
|
2566
2582
|
const images = await Promise.all(
|
|
2567
2583
|
message.mode.images.map(async (img) => {
|
|
2568
|
-
const downloaded = await
|
|
2584
|
+
const downloaded = await downloadImage.downloadImage(img.url);
|
|
2569
2585
|
return {
|
|
2570
2586
|
data: downloaded.base64,
|
|
2571
2587
|
mimeType: downloaded.mimeType
|
|
@@ -2573,7 +2589,7 @@ async function runCodex(opts) {
|
|
|
2573
2589
|
})
|
|
2574
2590
|
);
|
|
2575
2591
|
promptOptions = { images };
|
|
2576
|
-
|
|
2592
|
+
logger.logger.debug(`[Codex] Downloaded ${images.length} image(s)`);
|
|
2577
2593
|
}
|
|
2578
2594
|
if (!wasCreated || !backend?.isAlive) {
|
|
2579
2595
|
wasCreated = false;
|
|
@@ -2582,16 +2598,16 @@ async function runCodex(opts) {
|
|
|
2582
2598
|
if (nextResumeFile) {
|
|
2583
2599
|
resumeFile = nextResumeFile;
|
|
2584
2600
|
nextResumeFile = null;
|
|
2585
|
-
|
|
2601
|
+
logger.logger.debug("[Codex] Using resume file from mode change:", resumeFile);
|
|
2586
2602
|
} else if (first && envResumeFile) {
|
|
2587
2603
|
resumeFile = envResumeFile;
|
|
2588
|
-
|
|
2604
|
+
logger.logger.debug("[Codex] Using resume file from App-side resume:", resumeFile);
|
|
2589
2605
|
messageBuffer.addMessage("Resuming from previous session...", "status");
|
|
2590
2606
|
} else if (storedSessionIdForResume) {
|
|
2591
2607
|
const abortResumeFile = findCodexResumeFile(storedSessionIdForResume);
|
|
2592
2608
|
if (abortResumeFile) {
|
|
2593
2609
|
resumeFile = abortResumeFile;
|
|
2594
|
-
|
|
2610
|
+
logger.logger.debug("[Codex] Using resume file from aborted session:", resumeFile);
|
|
2595
2611
|
messageBuffer.addMessage("Resuming from aborted session...", "status");
|
|
2596
2612
|
}
|
|
2597
2613
|
storedSessionIdForResume = null;
|
|
@@ -2645,7 +2661,7 @@ async function runCodex(opts) {
|
|
|
2645
2661
|
}
|
|
2646
2662
|
} catch (error) {
|
|
2647
2663
|
const errMsg = formatUnknownCodexError(error);
|
|
2648
|
-
|
|
2664
|
+
logger.logger.warn("Error in codex session:", errMsg);
|
|
2649
2665
|
const isAbortError = error instanceof Error && error.name === "AbortError";
|
|
2650
2666
|
const isUserAbort = isAbortError || abortRequested;
|
|
2651
2667
|
if (isUserAbort && !abortFeedbackSent) {
|
|
@@ -2661,7 +2677,7 @@ async function runCodex(opts) {
|
|
|
2661
2677
|
session.sendSessionEvent({ type: "message", message: "Process exited unexpectedly" });
|
|
2662
2678
|
if (backend && backend.isAlive) {
|
|
2663
2679
|
storedSessionIdForResume = backend.getSessionId();
|
|
2664
|
-
|
|
2680
|
+
logger.logger.debug("[Codex] Stored session after unexpected error:", storedSessionIdForResume);
|
|
2665
2681
|
}
|
|
2666
2682
|
session.sendAgentMessage("codex", {
|
|
2667
2683
|
type: "task_complete",
|
|
@@ -2686,55 +2702,55 @@ async function runCodex(opts) {
|
|
|
2686
2702
|
}
|
|
2687
2703
|
}
|
|
2688
2704
|
} finally {
|
|
2689
|
-
|
|
2705
|
+
logger.logger.debug("[codex]: Final cleanup start");
|
|
2690
2706
|
logActiveHandles("cleanup-start");
|
|
2691
2707
|
if (reconnectionHandle) {
|
|
2692
|
-
|
|
2708
|
+
logger.logger.debug("[codex]: Cancelling offline reconnection");
|
|
2693
2709
|
reconnectionHandle.cancel();
|
|
2694
2710
|
}
|
|
2695
2711
|
try {
|
|
2696
|
-
|
|
2712
|
+
logger.logger.debug("[codex]: sendSessionDeath");
|
|
2697
2713
|
session.sendSessionDeath();
|
|
2698
|
-
|
|
2714
|
+
logger.logger.debug("[codex]: flush begin");
|
|
2699
2715
|
await session.flush();
|
|
2700
|
-
|
|
2701
|
-
|
|
2716
|
+
logger.logger.debug("[codex]: flush done");
|
|
2717
|
+
logger.logger.debug("[codex]: session.close begin");
|
|
2702
2718
|
await session.close();
|
|
2703
|
-
|
|
2719
|
+
logger.logger.debug("[codex]: session.close done");
|
|
2704
2720
|
} catch (e) {
|
|
2705
|
-
|
|
2721
|
+
logger.logger.debug("[codex]: Error while closing session", e);
|
|
2706
2722
|
}
|
|
2707
|
-
|
|
2723
|
+
logger.logger.debug("[codex]: backend.dispose begin");
|
|
2708
2724
|
try {
|
|
2709
2725
|
await backend?.dispose();
|
|
2710
2726
|
} catch {
|
|
2711
2727
|
}
|
|
2712
|
-
|
|
2713
|
-
|
|
2728
|
+
logger.logger.debug("[codex]: backend.dispose done");
|
|
2729
|
+
logger.logger.debug("[codex]: mcp.stop");
|
|
2714
2730
|
mcp.stop();
|
|
2715
2731
|
if (process.stdin.isTTY) {
|
|
2716
|
-
|
|
2732
|
+
logger.logger.debug("[codex]: setRawMode(false)");
|
|
2717
2733
|
try {
|
|
2718
2734
|
process.stdin.setRawMode(false);
|
|
2719
2735
|
} catch {
|
|
2720
2736
|
}
|
|
2721
2737
|
}
|
|
2722
2738
|
if (hasTTY) {
|
|
2723
|
-
|
|
2739
|
+
logger.logger.debug("[codex]: stdin.pause()");
|
|
2724
2740
|
try {
|
|
2725
2741
|
process.stdin.pause();
|
|
2726
2742
|
} catch {
|
|
2727
2743
|
}
|
|
2728
2744
|
}
|
|
2729
|
-
|
|
2745
|
+
logger.logger.debug("[codex]: clearInterval(keepAlive)");
|
|
2730
2746
|
clearInterval(keepAliveInterval);
|
|
2731
2747
|
if (inkInstance) {
|
|
2732
|
-
|
|
2748
|
+
logger.logger.debug("[codex]: inkInstance.unmount()");
|
|
2733
2749
|
inkInstance.unmount();
|
|
2734
2750
|
}
|
|
2735
2751
|
messageBuffer.clear();
|
|
2736
2752
|
logActiveHandles("cleanup-end");
|
|
2737
|
-
|
|
2753
|
+
logger.logger.debug("[codex]: Final cleanup completed");
|
|
2738
2754
|
}
|
|
2739
2755
|
}
|
|
2740
2756
|
|