@vexdo/cli 0.1.2 → 0.1.3
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/index.js +43 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -700,6 +700,29 @@ function formatElapsed(startedAt) {
|
|
|
700
700
|
const seconds = Math.max(0, Math.round((Date.now() - startedAt) / 1e3));
|
|
701
701
|
return `${String(seconds)}s`;
|
|
702
702
|
}
|
|
703
|
+
function buildVerboseStreamHandler(label) {
|
|
704
|
+
let partialLine = "";
|
|
705
|
+
return {
|
|
706
|
+
onData(chunk) {
|
|
707
|
+
partialLine += chunk.toString();
|
|
708
|
+
const lines = partialLine.split(/\r?\n/);
|
|
709
|
+
partialLine = lines.pop() ?? "";
|
|
710
|
+
for (const line of lines) {
|
|
711
|
+
if (!line) {
|
|
712
|
+
continue;
|
|
713
|
+
}
|
|
714
|
+
debug(`[codex:${label}] ${line}`);
|
|
715
|
+
}
|
|
716
|
+
},
|
|
717
|
+
flush() {
|
|
718
|
+
if (!partialLine) {
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
debug(`[codex:${label}] ${partialLine}`);
|
|
722
|
+
partialLine = "";
|
|
723
|
+
}
|
|
724
|
+
};
|
|
725
|
+
}
|
|
703
726
|
async function checkCodexAvailable() {
|
|
704
727
|
await new Promise((resolve, reject) => {
|
|
705
728
|
execFileCb("codex", ["--version"], { timeout: CODEX_TIMEOUT_MS, encoding: "utf8" }, (error) => {
|
|
@@ -718,10 +741,13 @@ async function exec(opts) {
|
|
|
718
741
|
debug(`[codex] starting (model=${opts.model}, cwd=${opts.cwd})`);
|
|
719
742
|
}
|
|
720
743
|
return await new Promise((resolve, reject) => {
|
|
744
|
+
let liveLogsAttached = false;
|
|
745
|
+
const stdoutHandler = buildVerboseStreamHandler("stdout");
|
|
746
|
+
const stderrHandler = buildVerboseStreamHandler("stderr");
|
|
721
747
|
const heartbeat = opts.verbose ? setInterval(() => {
|
|
722
748
|
debug(`[codex] still running (${formatElapsed(startedAt)})`);
|
|
723
749
|
}, VERBOSE_HEARTBEAT_MS) : null;
|
|
724
|
-
execFileCb(
|
|
750
|
+
const child = execFileCb(
|
|
725
751
|
"codex",
|
|
726
752
|
args,
|
|
727
753
|
{ cwd: opts.cwd, timeout: CODEX_TIMEOUT_MS, encoding: "utf8", maxBuffer: 10 * 1024 * 1024 },
|
|
@@ -729,14 +755,16 @@ async function exec(opts) {
|
|
|
729
755
|
if (heartbeat) {
|
|
730
756
|
clearInterval(heartbeat);
|
|
731
757
|
}
|
|
758
|
+
stdoutHandler.flush();
|
|
759
|
+
stderrHandler.flush();
|
|
732
760
|
const normalizedStdout = stdout.trimEnd();
|
|
733
761
|
const normalizedStderr = stderr.trimEnd();
|
|
734
762
|
if (opts.verbose) {
|
|
735
763
|
debug(`[codex] finished in ${formatElapsed(startedAt)}`);
|
|
736
|
-
if (normalizedStdout) {
|
|
764
|
+
if (!liveLogsAttached && normalizedStdout) {
|
|
737
765
|
debug(normalizedStdout);
|
|
738
766
|
}
|
|
739
|
-
if (normalizedStderr) {
|
|
767
|
+
if (!liveLogsAttached && normalizedStderr) {
|
|
740
768
|
debug(normalizedStderr);
|
|
741
769
|
}
|
|
742
770
|
}
|
|
@@ -755,6 +783,18 @@ async function exec(opts) {
|
|
|
755
783
|
});
|
|
756
784
|
}
|
|
757
785
|
);
|
|
786
|
+
if (opts.verbose) {
|
|
787
|
+
const stdout = child.stdout;
|
|
788
|
+
const stderr = child.stderr;
|
|
789
|
+
if (stdout) {
|
|
790
|
+
liveLogsAttached = true;
|
|
791
|
+
stdout.on("data", stdoutHandler.onData);
|
|
792
|
+
}
|
|
793
|
+
if (stderr) {
|
|
794
|
+
liveLogsAttached = true;
|
|
795
|
+
stderr.on("data", stderrHandler.onData);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
758
798
|
});
|
|
759
799
|
}
|
|
760
800
|
|