@commonlyai/cli 0.1.275 → 0.1.276
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/lib/adapters/codex.js +39 -17
package/package.json
CHANGED
|
@@ -901,33 +901,47 @@ const makeEventParser = () => {
|
|
|
901
901
|
let buffer = '';
|
|
902
902
|
let threadId = null;
|
|
903
903
|
let turnFailedMessage = null;
|
|
904
|
+
let turnCompleted = false;
|
|
905
|
+
|
|
906
|
+
const consumeLine = (raw) => {
|
|
907
|
+
const line = raw.trim();
|
|
908
|
+
if (!line) return;
|
|
909
|
+
try {
|
|
910
|
+
const evt = JSON.parse(line);
|
|
911
|
+
if (evt.type === 'thread.started' && evt.thread_id && !threadId) {
|
|
912
|
+
threadId = evt.thread_id;
|
|
913
|
+
} else if (evt.type === 'turn.completed') {
|
|
914
|
+
turnCompleted = true;
|
|
915
|
+
} else if (evt.type === 'turn.failed') {
|
|
916
|
+
// Capture the most recent — codex may emit multiple before exit.
|
|
917
|
+
turnFailedMessage = evt.error?.message || 'codex turn failed';
|
|
918
|
+
}
|
|
919
|
+
} catch {
|
|
920
|
+
// Non-JSON lines on stdout are unexpected but not fatal — skip.
|
|
921
|
+
}
|
|
922
|
+
};
|
|
904
923
|
|
|
905
924
|
const consume = (chunk) => {
|
|
906
925
|
buffer += chunk.toString();
|
|
907
926
|
let nl;
|
|
908
927
|
// eslint-disable-next-line no-cond-assign
|
|
909
928
|
while ((nl = buffer.indexOf('\n')) !== -1) {
|
|
910
|
-
|
|
929
|
+
consumeLine(buffer.slice(0, nl));
|
|
911
930
|
buffer = buffer.slice(nl + 1);
|
|
912
|
-
if (!line) continue;
|
|
913
|
-
try {
|
|
914
|
-
const evt = JSON.parse(line);
|
|
915
|
-
if (evt.type === 'thread.started' && evt.thread_id && !threadId) {
|
|
916
|
-
threadId = evt.thread_id;
|
|
917
|
-
} else if (evt.type === 'turn.failed') {
|
|
918
|
-
// Capture the most recent — codex may emit multiple before exit.
|
|
919
|
-
turnFailedMessage = evt.error?.message || 'codex turn failed';
|
|
920
|
-
}
|
|
921
|
-
} catch {
|
|
922
|
-
// Non-JSON lines on stdout are unexpected but not fatal — skip.
|
|
923
|
-
}
|
|
924
931
|
}
|
|
925
932
|
};
|
|
926
933
|
|
|
934
|
+
const flush = () => {
|
|
935
|
+
consumeLine(buffer);
|
|
936
|
+
buffer = '';
|
|
937
|
+
};
|
|
938
|
+
|
|
927
939
|
return {
|
|
928
940
|
consume,
|
|
941
|
+
flush,
|
|
929
942
|
get threadId() { return threadId; },
|
|
930
943
|
get turnFailedMessage() { return turnFailedMessage; },
|
|
944
|
+
get turnCompleted() { return turnCompleted; },
|
|
931
945
|
};
|
|
932
946
|
};
|
|
933
947
|
|
|
@@ -986,6 +1000,7 @@ const runCodex = ({
|
|
|
986
1000
|
// eslint-disable-next-line no-console
|
|
987
1001
|
if (reaped) console.warn(`[codex] ${reaped}`);
|
|
988
1002
|
if (timedOut) return reject(new Error(`codex timed out after ${timeoutMs}ms`));
|
|
1003
|
+
events.flush();
|
|
989
1004
|
if (events.turnFailedMessage) {
|
|
990
1005
|
// Surface the model-side failure message verbatim — the run loop posts
|
|
991
1006
|
// it as the agent's reply so the user sees what went wrong rather than
|
|
@@ -1002,7 +1017,7 @@ const runCodex = ({
|
|
|
1002
1017
|
if (code !== 0) {
|
|
1003
1018
|
return reject(adapterFailure('codex', stderr.trim(), { credentials, exitCode: code, limit: 500 }));
|
|
1004
1019
|
}
|
|
1005
|
-
resolve({ threadId: events.threadId });
|
|
1020
|
+
resolve({ threadId: events.threadId, turnCompleted: events.turnCompleted });
|
|
1006
1021
|
});
|
|
1007
1022
|
});
|
|
1008
1023
|
|
|
@@ -1169,7 +1184,7 @@ export default {
|
|
|
1169
1184
|
if (ctx.signal?.aborted) {
|
|
1170
1185
|
throw ctx.signal.reason || new Error('codex spawn cancelled before the process started');
|
|
1171
1186
|
}
|
|
1172
|
-
const { threadId } = await runCodex({
|
|
1187
|
+
const { threadId, turnCompleted } = await runCodex({
|
|
1173
1188
|
args,
|
|
1174
1189
|
cwd: ctx.cwd,
|
|
1175
1190
|
env: childEnv,
|
|
@@ -1194,11 +1209,18 @@ export default {
|
|
|
1194
1209
|
try {
|
|
1195
1210
|
text = (await readFile(outputFile, 'utf8')).trim();
|
|
1196
1211
|
} catch {
|
|
1197
|
-
//
|
|
1198
|
-
//
|
|
1212
|
+
// No file: a finished turn with no final message.
|
|
1213
|
+
// The run loop treats empty text as a silent turn and acknowledges it.
|
|
1199
1214
|
text = '';
|
|
1200
1215
|
}
|
|
1201
1216
|
|
|
1217
|
+
// A signal doesn't reach the exit code when codex runs through the npm
|
|
1218
|
+
// launcher: it re-raises SIGTERM or SIGHUP into its own handler and exits
|
|
1219
|
+
// 0. Resolving would read as a turn with nothing to say, and the messages
|
|
1220
|
+
// it held would never be answered. A final message counts as finished,
|
|
1221
|
+
// so a version that doesn't print turn.completed still posts its reply.
|
|
1222
|
+
if (!turnCompleted && !text) throw adapterFailure('codex', 'the turn stopped before it finished');
|
|
1223
|
+
|
|
1202
1224
|
// newSessionId precedence: thread_id from this turn (always emitted on
|
|
1203
1225
|
// a new session, often re-emitted on resume) > the persisted id we
|
|
1204
1226
|
// came in with > null. The wrapper persists whichever non-null value
|