@mindexec/cli 0.2.92 → 0.2.93
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 +2 -2
- package/server.js +78 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mindexec/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.93",
|
|
4
4
|
"description": "MindExec local runtime and bridge CLI",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"type": "module",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"node": ">=20"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@mindexec/remote": "^0.1.
|
|
50
|
+
"@mindexec/remote": "^0.1.15",
|
|
51
51
|
"@openai/codex-sdk": "^0.137.0",
|
|
52
52
|
"chokidar": "^3.6.0",
|
|
53
53
|
"cors": "^2.8.5",
|
package/server.js
CHANGED
|
@@ -2732,6 +2732,7 @@ const remoteHub = createRemoteHub({
|
|
|
2732
2732
|
});
|
|
2733
2733
|
|
|
2734
2734
|
const REMOTE_AGENT_STDIO_TAIL_CHARS = 12000;
|
|
2735
|
+
const REMOTE_AGENT_EARLY_EXIT_MS = 1200;
|
|
2735
2736
|
const REMOTE_AGENT_DEFAULT_ENGINE = 'auto';
|
|
2736
2737
|
let remoteAgentState = createRemoteAgentIdleState();
|
|
2737
2738
|
|
|
@@ -2778,6 +2779,71 @@ function appendRemoteAgentOutput(stream, chunk) {
|
|
|
2778
2779
|
remoteAgentState.updatedAt = new Date().toISOString();
|
|
2779
2780
|
}
|
|
2780
2781
|
|
|
2782
|
+
function summarizeRemoteAgentOutput(value, maxLength = 700) {
|
|
2783
|
+
const text = String(value || '').replace(/\s+/g, ' ').trim();
|
|
2784
|
+
if (text.length <= maxLength) {
|
|
2785
|
+
return text;
|
|
2786
|
+
}
|
|
2787
|
+
|
|
2788
|
+
return `...${text.slice(text.length - maxLength + 3)}`;
|
|
2789
|
+
}
|
|
2790
|
+
|
|
2791
|
+
function formatRemoteAgentFailureSummary(agent = remoteAgentState) {
|
|
2792
|
+
const details = [];
|
|
2793
|
+
if (agent.lastError) {
|
|
2794
|
+
details.push(agent.lastError);
|
|
2795
|
+
} else if (agent.signal) {
|
|
2796
|
+
details.push(`signal:${agent.signal}`);
|
|
2797
|
+
} else if (Number.isFinite(agent.exitCode)) {
|
|
2798
|
+
details.push(`exit:${agent.exitCode}`);
|
|
2799
|
+
}
|
|
2800
|
+
|
|
2801
|
+
const stderr = summarizeRemoteAgentOutput(agent.stderrTail);
|
|
2802
|
+
if (stderr) {
|
|
2803
|
+
details.push(`stderr=${stderr}`);
|
|
2804
|
+
}
|
|
2805
|
+
|
|
2806
|
+
const stdout = summarizeRemoteAgentOutput(agent.stdoutTail);
|
|
2807
|
+
if (stdout) {
|
|
2808
|
+
details.push(`stdout=${stdout}`);
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2811
|
+
return details.join(' | ') || 'remote-agent-failed';
|
|
2812
|
+
}
|
|
2813
|
+
|
|
2814
|
+
function waitForRemoteAgentEarlyExit(child, settleMs = REMOTE_AGENT_EARLY_EXIT_MS) {
|
|
2815
|
+
return new Promise(resolve => {
|
|
2816
|
+
if (!child || child.exitCode !== null || child.killed) {
|
|
2817
|
+
resolve(true);
|
|
2818
|
+
return;
|
|
2819
|
+
}
|
|
2820
|
+
|
|
2821
|
+
let settled = false;
|
|
2822
|
+
let timer = null;
|
|
2823
|
+
const cleanup = () => {
|
|
2824
|
+
if (timer) {
|
|
2825
|
+
clearTimeout(timer);
|
|
2826
|
+
}
|
|
2827
|
+
child.off('exit', onExit);
|
|
2828
|
+
child.off('error', onError);
|
|
2829
|
+
};
|
|
2830
|
+
const finish = value => {
|
|
2831
|
+
if (settled) {
|
|
2832
|
+
return;
|
|
2833
|
+
}
|
|
2834
|
+
settled = true;
|
|
2835
|
+
cleanup();
|
|
2836
|
+
resolve(value);
|
|
2837
|
+
};
|
|
2838
|
+
const onExit = () => finish(true);
|
|
2839
|
+
const onError = () => finish(true);
|
|
2840
|
+
|
|
2841
|
+
child.once('exit', onExit);
|
|
2842
|
+
child.once('error', onError);
|
|
2843
|
+
timer = setTimeout(() => finish(false), settleMs);
|
|
2844
|
+
});
|
|
2845
|
+
}
|
|
2846
|
+
|
|
2781
2847
|
function normalizeRemoteAgentEngine(value) {
|
|
2782
2848
|
const engine = String(value || REMOTE_AGENT_DEFAULT_ENGINE).trim().toLowerCase();
|
|
2783
2849
|
if (engine === 'fast' || engine === 'csharp' || engine === 'c#') {
|
|
@@ -2961,6 +3027,7 @@ async function startRemoteAgentConnection(options = {}) {
|
|
|
2961
3027
|
remoteAgentState.status = 'failed';
|
|
2962
3028
|
remoteAgentState.lastError = err?.message || String(err);
|
|
2963
3029
|
remoteAgentState.updatedAt = new Date().toISOString();
|
|
3030
|
+
logWarn('remote', `managed RemoteAgent failed: ${formatRemoteAgentFailureSummary()}`);
|
|
2964
3031
|
emitBridgeEvent('RemoteAgentFailed', serializeRemoteAgentState());
|
|
2965
3032
|
});
|
|
2966
3033
|
child.once('exit', (code, signal) => {
|
|
@@ -2972,6 +3039,11 @@ async function startRemoteAgentConnection(options = {}) {
|
|
|
2972
3039
|
if (code !== 0 && !remoteAgentState.lastError) {
|
|
2973
3040
|
remoteAgentState.lastError = signal ? `signal:${signal}` : `exit:${code}`;
|
|
2974
3041
|
}
|
|
3042
|
+
if (remoteAgentState.status === 'failed') {
|
|
3043
|
+
logWarn('remote', `managed RemoteAgent failed: ${formatRemoteAgentFailureSummary()}`);
|
|
3044
|
+
} else {
|
|
3045
|
+
logEvent('remote', `managed RemoteAgent exited ${formatKeyValue('code', code ?? 0)}`, 'remote');
|
|
3046
|
+
}
|
|
2975
3047
|
emitBridgeEvent(remoteAgentState.status === 'exited' ? 'RemoteAgentExited' : 'RemoteAgentFailed', serializeRemoteAgentState());
|
|
2976
3048
|
});
|
|
2977
3049
|
|
|
@@ -2981,6 +3053,12 @@ async function startRemoteAgentConnection(options = {}) {
|
|
|
2981
3053
|
'remote');
|
|
2982
3054
|
emitBridgeEvent('RemoteAgentStarted', serializeRemoteAgentState());
|
|
2983
3055
|
|
|
3056
|
+
const exitedEarly = await waitForRemoteAgentEarlyExit(child);
|
|
3057
|
+
if (exitedEarly) {
|
|
3058
|
+
const error = formatRemoteAgentFailureSummary();
|
|
3059
|
+
return { ok: false, error, agent: serializeRemoteAgentState() };
|
|
3060
|
+
}
|
|
3061
|
+
|
|
2984
3062
|
return { ok: true, alreadyRunning: false, agent: serializeRemoteAgentState() };
|
|
2985
3063
|
}
|
|
2986
3064
|
|