@openagents-org/agent-launcher 0.2.218 → 0.2.220
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/node_modules/ws/LICENSE +20 -0
- package/node_modules/ws/README.md +548 -0
- package/node_modules/ws/browser.js +8 -0
- package/node_modules/ws/index.js +22 -0
- package/node_modules/ws/lib/buffer-util.js +131 -0
- package/node_modules/ws/lib/constants.js +19 -0
- package/node_modules/ws/lib/event-target.js +292 -0
- package/node_modules/ws/lib/extension.js +203 -0
- package/node_modules/ws/lib/limiter.js +55 -0
- package/node_modules/ws/lib/permessage-deflate.js +528 -0
- package/node_modules/ws/lib/receiver.js +706 -0
- package/node_modules/ws/lib/sender.js +602 -0
- package/node_modules/ws/lib/stream.js +161 -0
- package/node_modules/ws/lib/subprotocol.js +62 -0
- package/node_modules/ws/lib/validation.js +152 -0
- package/node_modules/ws/lib/websocket-server.js +554 -0
- package/node_modules/ws/lib/websocket.js +1393 -0
- package/node_modules/ws/package.json +70 -0
- package/node_modules/ws/wrapper.mjs +21 -0
- package/package.json +5 -2
- package/registry.json +12 -2
- package/src/adapters/claude.js +13 -9
- package/src/adapters/codearts.js +1 -0
- package/src/adapters/codex.js +49 -9
- package/src/adapters/deepseek-runtime.js +6 -2
- package/src/adapters/kimi-stream.js +78 -5
- package/src/adapters/kimi.js +114 -24
- package/src/adapters/mimo-code.js +1 -0
- package/src/adapters/openclaw.js +24 -19
- package/src/adapters/opencode.js +55 -2
- package/src/adapters/utils.js +11 -0
- package/src/daemon.js +4 -2
- package/src/installer.js +206 -36
- package/src/native-build.js +132 -0
- package/src/probe.js +88 -7
- package/src/utils.js +123 -12
package/src/adapters/kimi.js
CHANGED
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
const fs = require('fs');
|
|
40
40
|
const os = require('os');
|
|
41
41
|
const path = require('path');
|
|
42
|
+
const { StringDecoder } = require('string_decoder');
|
|
42
43
|
const { execSync } = require('child_process');
|
|
43
44
|
// spawn() here is the WSL bridge from ../wsl: same signature as
|
|
44
45
|
// child_process.spawn, and a straight pass-through unless the resolved CLI
|
|
@@ -59,6 +60,7 @@ const {
|
|
|
59
60
|
classifyKimiVersion,
|
|
60
61
|
classifyKimiError,
|
|
61
62
|
encodeKimiWorkDirKey,
|
|
63
|
+
KimiWireTracker,
|
|
62
64
|
KIMI_MCP_SERVER_NAME,
|
|
63
65
|
KIMI_HOME_LINKS,
|
|
64
66
|
kimiHomeName,
|
|
@@ -76,11 +78,21 @@ const DEFAULT_MODEL = 'kimi-k2.6';
|
|
|
76
78
|
// life is any stdout or stderr, or a write to the run's session journal. The
|
|
77
79
|
// journal is the only trace a subagent leaves: print mode never forwards its
|
|
78
80
|
// events, so a main agent waiting on an `Agent` tool call is otherwise mute.
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
+
//
|
|
82
|
+
// Print mode is also mute while the model works on a step — it streams, but
|
|
83
|
+
// nothing reaches stdout, stderr or the journal until the step is done — and
|
|
84
|
+
// while a tool runs, a shell command or a background task the run waits on
|
|
85
|
+
// (verified v2.5.2). Five minutes of that stopped working runs: a long
|
|
86
|
+
// thinking step, or a model writing a long script and then running it. So a
|
|
87
|
+
// quiet stretch while the journal shows a tool still running
|
|
88
|
+
// (KimiWireTracker) does not count against MAX, only against TOOL_MAX; and
|
|
89
|
+
// MAX allows a full step. Our output cap is 32768 tokens
|
|
90
|
+
// (DEFAULT_MAX_COMPLETION_TOKENS), about 14 min at 40 tokens/s. Kimi's
|
|
91
|
+
// provider retry backoff can reach ~1 min between attempts.
|
|
81
92
|
const WATCHDOG_INTERVAL_MS = 15_000;
|
|
82
|
-
const WATCHDOG_NUDGE_AT = 2;
|
|
83
|
-
const WATCHDOG_MAX =
|
|
93
|
+
const WATCHDOG_NUDGE_AT = 2; // ~30s of silence → "still working"
|
|
94
|
+
const WATCHDOG_MAX = 60; // ~15 min of silence, no tool running → kill
|
|
95
|
+
const WATCHDOG_TOOL_MAX = 120; // ~30 min of silence while a tool runs → kill
|
|
84
96
|
|
|
85
97
|
// Version check cache: keyed by resolved binary path so repeated messages
|
|
86
98
|
// don't re-spawn `kimi --version`, yet an install/upgrade is re-detected.
|
|
@@ -154,6 +166,7 @@ class KimiAdapter extends LlmDirectAdapter {
|
|
|
154
166
|
this._watchdogIntervalMs = WATCHDOG_INTERVAL_MS;
|
|
155
167
|
this._watchdogNudgeAt = WATCHDOG_NUDGE_AT;
|
|
156
168
|
this._watchdogMax = WATCHDOG_MAX;
|
|
169
|
+
this._watchdogToolMax = WATCHDOG_TOOL_MAX;
|
|
157
170
|
this._sessionsFile = path.join(
|
|
158
171
|
os.homedir(), '.openagents', 'sessions',
|
|
159
172
|
`${this.workspaceId}_${this.agentName}_kimi.json`,
|
|
@@ -653,6 +666,7 @@ class KimiAdapter extends LlmDirectAdapter {
|
|
|
653
666
|
stderrText: result.stderrText,
|
|
654
667
|
retryMessage: result.retryMessage,
|
|
655
668
|
timedOutMs: result.timedOutMs,
|
|
669
|
+
timedOutInTool: result.timedOutInTool,
|
|
656
670
|
});
|
|
657
671
|
try { await this.sendError(channel, userMessage); } catch {}
|
|
658
672
|
} else {
|
|
@@ -764,35 +778,93 @@ class KimiAdapter extends LlmDirectAdapter {
|
|
|
764
778
|
let known = [];
|
|
765
779
|
try { known = fs.readdirSync(bucket); } catch {}
|
|
766
780
|
const s = args.indexOf('-S');
|
|
767
|
-
|
|
781
|
+
const watch = {
|
|
782
|
+
bucket, known: new Set(known), resumeId: s >= 0 ? args[s + 1] : null, wires: new Map(), since: Date.now(),
|
|
783
|
+
};
|
|
784
|
+
// A resumed session's journal is read on from where it stands now. Not
|
|
785
|
+
// needed for correctness (records from before `since` open nothing), but
|
|
786
|
+
// a long session's journal is not read whole on every run.
|
|
787
|
+
for (const name of this._runSessionDirs(watch)) {
|
|
788
|
+
const file = this._mainWirePath(watch, name);
|
|
789
|
+
try {
|
|
790
|
+
const st = fs.statSync(file);
|
|
791
|
+
watch.wires.set(file, this._newWire(watch, st.size, st.ino));
|
|
792
|
+
} catch {}
|
|
793
|
+
}
|
|
794
|
+
return watch;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
/** This run's session directories: the resumed one, plus any created since the run started. */
|
|
798
|
+
_runSessionDirs(watch) {
|
|
799
|
+
let names;
|
|
800
|
+
try { names = fs.readdirSync(watch.bucket); } catch { return []; }
|
|
801
|
+
return names.filter((name) => !watch.known.has(name) || (!!watch.resumeId &&
|
|
802
|
+
(name === watch.resumeId || name === `session_${watch.resumeId}`)));
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
_mainWirePath(watch, name) {
|
|
806
|
+
return path.join(watch.bucket, name, 'agents', 'main', 'wire.jsonl');
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
_newWire(watch, offset = 0, ino = null) {
|
|
810
|
+
return { offset, ino, decoder: new StringDecoder('utf8'), tracker: new KimiWireTracker({ since: watch.since }) };
|
|
768
811
|
}
|
|
769
812
|
|
|
770
813
|
/**
|
|
771
|
-
* Newest write (ms) inside this run's session journals
|
|
772
|
-
*
|
|
773
|
-
*
|
|
774
|
-
* longer, never stops one early. 0 when there is nothing to look at.
|
|
814
|
+
* Newest write (ms) inside this run's session journals. A second fresh run
|
|
815
|
+
* in the same directory can be counted too; that only ever keeps a run
|
|
816
|
+
* alive longer, never stops one early. 0 when there is nothing to look at.
|
|
775
817
|
*/
|
|
776
818
|
_latestKimiSessionWrite(watch) {
|
|
777
|
-
let names;
|
|
778
|
-
try { names = fs.readdirSync(watch.bucket); } catch { return 0; }
|
|
779
819
|
let latest = 0;
|
|
780
|
-
for (const name of
|
|
781
|
-
const resumed = !!watch.resumeId &&
|
|
782
|
-
(name === watch.resumeId || name === `session_${watch.resumeId}`);
|
|
783
|
-
if (watch.known.has(name) && !resumed) continue;
|
|
820
|
+
for (const name of this._runSessionDirs(watch)) {
|
|
784
821
|
latest = Math.max(latest, newestMtimeMs(path.join(watch.bucket, name), 3));
|
|
785
822
|
}
|
|
786
823
|
return latest;
|
|
787
824
|
}
|
|
788
825
|
|
|
826
|
+
/**
|
|
827
|
+
* Whether this run's main agent has a tool call or a background task still
|
|
828
|
+
* running, by its session journal (see KimiWireTracker). Each journal is
|
|
829
|
+
* read on from where the last look stopped — unless Kimi replaced it: it
|
|
830
|
+
* rewrites a journal whose last line was cut off (a run stopped mid-write)
|
|
831
|
+
* to its valid prefix, and migrates old ones, both as a new file. The old
|
|
832
|
+
* offset then points past this run's records; such a file is read again
|
|
833
|
+
* from the start.
|
|
834
|
+
*/
|
|
835
|
+
_kimiToolRunning(watch) {
|
|
836
|
+
let running = false;
|
|
837
|
+
for (const name of this._runSessionDirs(watch)) {
|
|
838
|
+
const file = this._mainWirePath(watch, name);
|
|
839
|
+
let wire = watch.wires.get(file);
|
|
840
|
+
try {
|
|
841
|
+
const st = fs.statSync(file);
|
|
842
|
+
if (!wire || st.ino !== wire.ino || st.size < wire.offset) {
|
|
843
|
+
wire = this._newWire(watch, 0, st.ino);
|
|
844
|
+
watch.wires.set(file, wire);
|
|
845
|
+
}
|
|
846
|
+
const size = st.size;
|
|
847
|
+
if (size > wire.offset) {
|
|
848
|
+
const buf = Buffer.alloc(size - wire.offset);
|
|
849
|
+
const fd = fs.openSync(file, 'r');
|
|
850
|
+
try { fs.readSync(fd, buf, 0, buf.length, wire.offset); } finally { fs.closeSync(fd); }
|
|
851
|
+
wire.offset = size;
|
|
852
|
+
wire.tracker.push(wire.decoder.write(buf));
|
|
853
|
+
}
|
|
854
|
+
} catch {}
|
|
855
|
+
if (wire && wire.tracker.busy) running = true;
|
|
856
|
+
}
|
|
857
|
+
return running;
|
|
858
|
+
}
|
|
859
|
+
|
|
789
860
|
/**
|
|
790
861
|
* Spawn one `kimi -p … --output-format stream-json` run, stream-parse it,
|
|
791
862
|
* and resolve a summary:
|
|
792
863
|
* { ok, finalText, sessionId, anyOutput, userStopped,
|
|
793
|
-
* exitCode, exitSignal, stderrText, retryMessage, timedOutMs }
|
|
864
|
+
* exitCode, exitSignal, stderrText, retryMessage, timedOutMs, timedOutInTool }
|
|
794
865
|
* `ok` is exit code 0; `finalText` is the LAST assistant text of the turn;
|
|
795
|
-
* `timedOutMs` is non-zero when the idle watchdog stopped the run
|
|
866
|
+
* `timedOutMs` is non-zero when the idle watchdog stopped the run, and
|
|
867
|
+
* `timedOutInTool` says a tool call or background task was running then.
|
|
796
868
|
*/
|
|
797
869
|
_runKimi(channel, kimiBin, args, workingDir) {
|
|
798
870
|
// Stopped while this turn was being prepared: start nothing (no tokens).
|
|
@@ -837,6 +909,7 @@ class KimiAdapter extends LlmDirectAdapter {
|
|
|
837
909
|
stderrText: '',
|
|
838
910
|
retryMessage: '',
|
|
839
911
|
timedOutMs: 0,
|
|
912
|
+
timedOutInTool: false,
|
|
840
913
|
};
|
|
841
914
|
|
|
842
915
|
return new Promise((resolve) => {
|
|
@@ -846,7 +919,9 @@ class KimiAdapter extends LlmDirectAdapter {
|
|
|
846
919
|
let lastDataMs = Date.now();
|
|
847
920
|
let seenSessionWriteMs = lastDataMs;
|
|
848
921
|
let loggedSessionAlive = false;
|
|
849
|
-
let silences = 0;
|
|
922
|
+
let silences = 0; // quiet ticks with no tool running
|
|
923
|
+
let quietTicks = 0; // every quiet tick since the last sign of life
|
|
924
|
+
let loggedToolRunning = false;
|
|
850
925
|
let queue = Promise.resolve();
|
|
851
926
|
|
|
852
927
|
const cleanup = () => {
|
|
@@ -912,6 +987,7 @@ class KimiAdapter extends LlmDirectAdapter {
|
|
|
912
987
|
proc.stdout.on('data', (chunk) => {
|
|
913
988
|
lastDataMs = Date.now();
|
|
914
989
|
silences = 0;
|
|
990
|
+
quietTicks = 0;
|
|
915
991
|
const msgs = parser.push(chunk);
|
|
916
992
|
for (const m of msgs) queue = queue.then(() => handleMessage(m)).catch(() => {});
|
|
917
993
|
});
|
|
@@ -922,6 +998,7 @@ class KimiAdapter extends LlmDirectAdapter {
|
|
|
922
998
|
proc.stderr.on('data', (chunk) => {
|
|
923
999
|
lastDataMs = Date.now();
|
|
924
1000
|
silences = 0;
|
|
1001
|
+
quietTicks = 0;
|
|
925
1002
|
state.stderrText += chunk.toString('utf-8');
|
|
926
1003
|
if (state.stderrText.length > 64 * 1024) {
|
|
927
1004
|
state.stderrText = state.stderrText.slice(-32 * 1024);
|
|
@@ -933,7 +1010,7 @@ class KimiAdapter extends LlmDirectAdapter {
|
|
|
933
1010
|
watchdogTimer = setInterval(async () => {
|
|
934
1011
|
if (settled) return;
|
|
935
1012
|
const elapsed = Date.now() - lastDataMs;
|
|
936
|
-
if (elapsed < intervalMs) { silences = 0; return; }
|
|
1013
|
+
if (elapsed < intervalMs) { silences = 0; quietTicks = 0; return; }
|
|
937
1014
|
// Both pipes are quiet. A subagent still working only shows up in the
|
|
938
1015
|
// session journal, so a fresh write there resets the count too.
|
|
939
1016
|
const wrote = this._latestKimiSessionWrite(sessionWatch);
|
|
@@ -941,32 +1018,45 @@ class KimiAdapter extends LlmDirectAdapter {
|
|
|
941
1018
|
seenSessionWriteMs = wrote;
|
|
942
1019
|
lastDataMs = Date.now();
|
|
943
1020
|
silences = 0;
|
|
1021
|
+
quietTicks = 0;
|
|
944
1022
|
if (!loggedSessionAlive) {
|
|
945
1023
|
loggedSessionAlive = true;
|
|
946
1024
|
this._log(`Watchdog: kimi quiet on ${channel} but its session is still being written — keeping it alive`);
|
|
947
1025
|
}
|
|
948
1026
|
return;
|
|
949
1027
|
}
|
|
950
|
-
|
|
1028
|
+
// A tool still running (see KimiWireTracker): the run is busy, and
|
|
1029
|
+
// print mode says nothing until the tool ends. Such a stretch is
|
|
1030
|
+
// bounded by _watchdogToolMax, not _watchdogMax.
|
|
1031
|
+
const toolRunning = this._kimiToolRunning(sessionWatch);
|
|
1032
|
+
if (toolRunning && !loggedToolRunning) {
|
|
1033
|
+
loggedToolRunning = true;
|
|
1034
|
+
this._log(`Watchdog: kimi quiet on ${channel} but a tool it started is still running — keeping it alive`);
|
|
1035
|
+
}
|
|
1036
|
+
quietTicks++;
|
|
1037
|
+
if (toolRunning) silences = 0;
|
|
1038
|
+
else silences++;
|
|
951
1039
|
// Deliberately NOT touching lastDataMs here: it marks the last real
|
|
952
1040
|
// sign of life, and the data handlers above already reset `silences`
|
|
953
1041
|
// themselves. Refreshing it on a silent tick parked the next tick's
|
|
954
1042
|
// `elapsed` right on the interval boundary, where an early-firing
|
|
955
1043
|
// timer (routine on Windows) read as "data just arrived" and reset
|
|
956
1044
|
// the count — so a genuinely hung run was never stopped.
|
|
957
|
-
if (
|
|
1045
|
+
if (quietTicks === this._watchdogNudgeAt) {
|
|
958
1046
|
try { await this.sendStatus(channel, 'Still working...'); } catch {}
|
|
959
1047
|
}
|
|
960
|
-
if (silences >= this._watchdogMax) {
|
|
1048
|
+
if (toolRunning ? quietTicks >= this._watchdogToolMax : silences >= this._watchdogMax) {
|
|
961
1049
|
// Stop ticking before the (awaited) kill: _stopProcess can take
|
|
962
1050
|
// seconds to escalate, and a tick landing inside that wait would
|
|
963
1051
|
// re-log, re-kill and keep inflating timedOutMs past the budget.
|
|
964
1052
|
clearInterval(watchdogTimer);
|
|
965
|
-
const silentMs =
|
|
966
|
-
this._log(`Watchdog: kimi silent ${Math.round(silentMs / 1000)}s on ${channel}
|
|
1053
|
+
const silentMs = Date.now() - lastDataMs;
|
|
1054
|
+
this._log(`Watchdog: kimi silent ${Math.round(silentMs / 1000)}s on ${channel}`
|
|
1055
|
+
+ `${toolRunning ? ' with a tool still running' : ''} — killing`);
|
|
967
1056
|
// Its own field, not stderr: tool noise already there used to leave
|
|
968
1057
|
// the user with nothing but the signal name.
|
|
969
1058
|
state.timedOutMs = silentMs;
|
|
1059
|
+
state.timedOutInTool = toolRunning;
|
|
970
1060
|
await this._stopProcess(proc);
|
|
971
1061
|
}
|
|
972
1062
|
}, intervalMs);
|
|
@@ -92,6 +92,7 @@ const FAILURE_MESSAGES = {
|
|
|
92
92
|
process_crashed: 'MiMo Code exited unexpectedly. Open diagnostics or retry.',
|
|
93
93
|
cwd_unavailable: "MiMo Code's working directory is not accessible. Check the agent's configured path (or agent home) permissions.",
|
|
94
94
|
session_missing: 'MiMo Code no longer has this conversation\'s session. Send the message again to start a new one.',
|
|
95
|
+
config_invalid: 'MiMo Code would not start because one of its config files is invalid — the file and what is wrong with it are below. Correct or remove that entry, then retry.',
|
|
95
96
|
unknown_error: 'MiMo Code failed for an undetermined reason. Open diagnostics or retry.',
|
|
96
97
|
};
|
|
97
98
|
|
package/src/adapters/openclaw.js
CHANGED
|
@@ -711,10 +711,19 @@ class OpenClawAdapter extends BaseAdapter {
|
|
|
711
711
|
const text = String(stderr || '');
|
|
712
712
|
const start = text.search(/\{\s*"payloads"/);
|
|
713
713
|
if (start < 0) return text;
|
|
714
|
-
|
|
715
|
-
|
|
714
|
+
const end = OpenClawAdapter._jsonObjectEnd(text, start);
|
|
715
|
+
return text.slice(0, start) + (end < 0 ? '' : text.slice(end));
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* Index just past the `}` that closes the JSON object opening at `start`,
|
|
720
|
+
* or -1 if it never closes. Braces inside JSON strings are not structure: a
|
|
721
|
+
* reply that quotes the end of a code block, or a lone "}", once cut the
|
|
722
|
+
* envelope short, and the whole reply was dropped as "No response
|
|
723
|
+
* generated". String contents are skipped, honoring backslash escapes.
|
|
724
|
+
*/
|
|
725
|
+
static _jsonObjectEnd(text, start) {
|
|
716
726
|
let depth = 0;
|
|
717
|
-
let end = text.length;
|
|
718
727
|
let inString = false;
|
|
719
728
|
for (let i = start; i < text.length; i++) {
|
|
720
729
|
const ch = text[i];
|
|
@@ -723,9 +732,9 @@ class OpenClawAdapter extends BaseAdapter {
|
|
|
723
732
|
else if (ch === '"') inString = false;
|
|
724
733
|
} else if (ch === '"') inString = true;
|
|
725
734
|
else if (ch === '{') depth++;
|
|
726
|
-
else if (ch === '}' && --depth === 0)
|
|
735
|
+
else if (ch === '}' && --depth === 0) return i + 1;
|
|
727
736
|
}
|
|
728
|
-
return
|
|
737
|
+
return -1;
|
|
729
738
|
}
|
|
730
739
|
|
|
731
740
|
/**
|
|
@@ -754,20 +763,16 @@ class OpenClawAdapter extends BaseAdapter {
|
|
|
754
763
|
// Find the JSON by looking for '{"payloads"' or the last complete JSON object.
|
|
755
764
|
let jsonStr = null;
|
|
756
765
|
|
|
757
|
-
// Strategy 1:
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
const
|
|
762
|
-
if (
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
for (let i = payloadsIdx; i < text.length; i++) {
|
|
768
|
-
if (text[i] === '{') depth++;
|
|
769
|
-
else if (text[i] === '}') { depth--; if (depth === 0) { jsonStr = text.slice(payloadsIdx, i + 1); break; } }
|
|
770
|
-
}
|
|
766
|
+
// Strategy 1: each {"payloads" or { "payloads" (with whitespace), up to
|
|
767
|
+
// the brace that closes it. The first one that parses is the envelope; one
|
|
768
|
+
// that does not (a trace line quoting a cut-off envelope) is skipped.
|
|
769
|
+
for (const match of text.matchAll(/\{\s*"payloads"/g)) {
|
|
770
|
+
const end = OpenClawAdapter._jsonObjectEnd(text, match.index);
|
|
771
|
+
if (end < 0) continue;
|
|
772
|
+
const candidate = text.slice(match.index, end);
|
|
773
|
+
try { JSON.parse(candidate); } catch { continue; }
|
|
774
|
+
jsonStr = candidate;
|
|
775
|
+
break;
|
|
771
776
|
}
|
|
772
777
|
|
|
773
778
|
// Strategy 2: find last '{' that starts a valid JSON with "payloads"
|
package/src/adapters/opencode.js
CHANGED
|
@@ -21,7 +21,7 @@ const { execSync } = require('child_process');
|
|
|
21
21
|
const { spawn } = require('../wsl');
|
|
22
22
|
|
|
23
23
|
const BaseAdapter = require('./base');
|
|
24
|
-
const { formatAttachmentsForPrompt, redactSecrets } = require('./utils');
|
|
24
|
+
const { formatAttachmentsForPrompt, redactSecrets, stripAnsi } = require('./utils');
|
|
25
25
|
const { buildOpenCodeSkillMd, buildOpenCodeSystemPrompt, workspaceSkillName } = require('./workspace-prompt');
|
|
26
26
|
const { whichBinary, whereBinary, getEnhancedEnv } = require('../paths');
|
|
27
27
|
const { isPostinstallStub, isPostinstallStubOutput } = require('../postinstall-stub');
|
|
@@ -91,6 +91,7 @@ const FAILURE_MESSAGES = {
|
|
|
91
91
|
permission_denied: 'OpenCode could not get permission for a tool call. Check the agent’s explicit deny rules or file access settings; sending continue alone will not change them.',
|
|
92
92
|
process_crashed: 'OpenCode exited unexpectedly. Open diagnostics or retry.',
|
|
93
93
|
cwd_unavailable: "OpenCode's working directory is not accessible. Check the agent's configured path (or agent home) permissions.",
|
|
94
|
+
config_invalid: 'OpenCode would not start because one of its config files is invalid — the file and what is wrong with it are below. OpenCode reads it on every run, so every message fails until it is fixed: correct or remove that entry, then retry.',
|
|
94
95
|
unknown_error: 'OpenCode failed for an undetermined reason. Open diagnostics or retry.',
|
|
95
96
|
};
|
|
96
97
|
|
|
@@ -1373,6 +1374,9 @@ class OpenCodeAdapter extends BaseAdapter {
|
|
|
1373
1374
|
* { category, diagnostic, detail }.
|
|
1374
1375
|
*/
|
|
1375
1376
|
static _classifyFailure({ code, signal, stdout, stderr, stdoutErr } = {}) {
|
|
1377
|
+
// OpenCode colours its errors even into a pipe; quoted as they came, the
|
|
1378
|
+
// channel showed "\x1b[91m\x1b[1mError: \x1b[0m…".
|
|
1379
|
+
stderr = stripAnsi(stderr);
|
|
1376
1380
|
const err = stdoutErr || OpenCodeAdapter._extractErrorFromStdout(stdout || '');
|
|
1377
1381
|
const status = err && err.status ? String(err.status) : '';
|
|
1378
1382
|
const msg = (err && err.message) || '';
|
|
@@ -1383,9 +1387,15 @@ class OpenCodeAdapter extends BaseAdapter {
|
|
|
1383
1387
|
const hay = `${name} ${status} ${msg} ${stderr || ''}`.toLowerCase();
|
|
1384
1388
|
const has = (re) => re.test(hay);
|
|
1385
1389
|
|
|
1390
|
+
const configError = OpenCodeAdapter._configError(stderr);
|
|
1386
1391
|
let category;
|
|
1387
1392
|
if (isPostinstallStubOutput(hay)) {
|
|
1388
1393
|
category = 'install_incomplete';
|
|
1394
|
+
} else if (configError) {
|
|
1395
|
+
// Checked before the provider patterns: what is wrong with the file is
|
|
1396
|
+
// free text ("Unrecognized key: model", "got {…401…}") that would read
|
|
1397
|
+
// as a bad model or a rejected key.
|
|
1398
|
+
category = 'config_invalid';
|
|
1389
1399
|
} else if (has(/(?:unrecognized|unknown) (?:flag|option|argument)s?:?\s*['"`]?--?[a-z]/)) {
|
|
1390
1400
|
// The CLI refused a flag this adapter always passes, so it is not a
|
|
1391
1401
|
// build we support (one whose version string we could not read gets
|
|
@@ -1419,10 +1429,53 @@ class OpenCodeAdapter extends BaseAdapter {
|
|
|
1419
1429
|
category = 'unknown_error';
|
|
1420
1430
|
}
|
|
1421
1431
|
|
|
1422
|
-
const detail =
|
|
1432
|
+
const detail = configError
|
|
1433
|
+
? OpenCodeAdapter._redact(configError).slice(0, 500)
|
|
1434
|
+
: OpenCodeAdapter._redact(msg || stderr || '').slice(0, 200);
|
|
1423
1435
|
return { category, diagnostic, detail };
|
|
1424
1436
|
}
|
|
1425
1437
|
|
|
1438
|
+
/**
|
|
1439
|
+
* OpenCode's refusal of a config file, as one line: which file, and what is
|
|
1440
|
+
* wrong with it — or null. Its two shapes (opencode-ai 1.17.11):
|
|
1441
|
+
*
|
|
1442
|
+
* Error: Configuration is invalid at <file>
|
|
1443
|
+
* ↳ Expected { readonly "type": "local", ... } | …, got {"url":"…"} mcp.upsy
|
|
1444
|
+
* ↳ Missing key mcp.upsy.enabled
|
|
1445
|
+
*
|
|
1446
|
+
* Error: Config file at <file> is not valid JSON(C):
|
|
1447
|
+
* --- JSONC Input --- … --- Errors ---
|
|
1448
|
+
* ValueExpected at line 1, column 15
|
|
1449
|
+
* Line 1: {"provider": {,}
|
|
1450
|
+
* ^
|
|
1451
|
+
*
|
|
1452
|
+
* The first 200 characters of stderr usually ended inside the file's path,
|
|
1453
|
+
* before the reason.
|
|
1454
|
+
*/
|
|
1455
|
+
static _configError(text) {
|
|
1456
|
+
const lines = stripAnsi(text).split(/\r?\n/);
|
|
1457
|
+
// OpenCode's own error line, not the phrase quoted somewhere else.
|
|
1458
|
+
const at = lines.findIndex((l) => /^\s*(?:error:\s*)?(?:configuration is invalid at |config file at .+ is not valid json)/i.test(l));
|
|
1459
|
+
if (at < 0) return null;
|
|
1460
|
+
const head = lines[at].trim().replace(/^error:\s*/i, '').replace(/:\s*$/, '');
|
|
1461
|
+
const reasons = [];
|
|
1462
|
+
for (const l of lines.slice(at + 1)) {
|
|
1463
|
+
const m = l.trim().match(/^↳\s*(.+)$/);
|
|
1464
|
+
if (m) reasons.push(m[1]);
|
|
1465
|
+
}
|
|
1466
|
+
if (!reasons.length) {
|
|
1467
|
+
const start = lines.findIndex((l) => l.trim() === '--- Errors ---');
|
|
1468
|
+
for (const l of start < 0 ? [] : lines.slice(start + 1)) {
|
|
1469
|
+
const t = l.trim();
|
|
1470
|
+
if (/^---/.test(t)) break;
|
|
1471
|
+
// The echoed source line and its caret, not reasons.
|
|
1472
|
+
if (!t || /^line \d+:/i.test(t) || /^\^+$/.test(t)) continue;
|
|
1473
|
+
reasons.push(t);
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
return reasons.length ? `${head}: ${reasons.join('; ')}` : head;
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1426
1479
|
/** Category for an exit-0 run that produced no final assistant text. */
|
|
1427
1480
|
static _emptyExitCategory(stdout) {
|
|
1428
1481
|
const raw = String(stdout || '').trim();
|
package/src/adapters/utils.js
CHANGED
|
@@ -272,6 +272,16 @@ function networkErrorText(err) {
|
|
|
272
272
|
return inner || err.code || String(err) || 'unknown network error';
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
+
// Terminal escape sequences (colour, cursor). A CLI that colours its errors
|
|
276
|
+
// writes them to a pipe too, and quoted into a channel they show as
|
|
277
|
+
// "\x1b[91m\x1b[1mError: \x1b[0m…".
|
|
278
|
+
const ANSI_RE = /\x1b\[[0-9;?]*[ -/]*[@-~]/g;
|
|
279
|
+
|
|
280
|
+
/** `text` with terminal escape sequences removed. */
|
|
281
|
+
function stripAnsi(text) {
|
|
282
|
+
return String(text || '').replace(ANSI_RE, '');
|
|
283
|
+
}
|
|
284
|
+
|
|
275
285
|
/** CLI output with the known-harmless lines taken out. */
|
|
276
286
|
function stripCliNoise(text) {
|
|
277
287
|
return String(text || '').split(/\r?\n/).filter((l) => !BENIGN_CLI_OUTPUT.test(l)).join('\n');
|
|
@@ -282,6 +292,7 @@ module.exports = {
|
|
|
282
292
|
networkErrorText,
|
|
283
293
|
BENIGN_CLI_OUTPUT,
|
|
284
294
|
stripCliNoise,
|
|
295
|
+
stripAnsi,
|
|
285
296
|
decodeConsoleOutput,
|
|
286
297
|
generateSessionTitle,
|
|
287
298
|
formatAttachmentsForPrompt,
|
package/src/daemon.js
CHANGED
|
@@ -44,8 +44,10 @@ const RUNTIME_DETECT_TIMEOUT_MS = 90 * 1000;
|
|
|
44
44
|
// not installed). Time alone does not change them, and re-running them every
|
|
45
45
|
// hour re-reported the same failure all day; they are swept daily, and again
|
|
46
46
|
// as soon as detection sees the type installed or signed in.
|
|
47
|
-
const SETUP_INCOMPLETE = new Set(['not_ready', 'not_logged_in', 'missing_api_key', 'not_installed', 'install_failed']);
|
|
47
|
+
const SETUP_INCOMPLETE = new Set(['not_ready', 'not_logged_in', 'missing_api_key', 'not_installed', 'install_failed', 'install_incomplete']);
|
|
48
48
|
const SETUP_INCOMPLETE_MAX_AGE_MS = 24 * 3600 * 1000;
|
|
49
|
+
// Probe results a runtime reinstall fixes: tested again as soon as one succeeds.
|
|
50
|
+
const REPROBE_AFTER_REPAIR = new Set(['version_incompatible', 'install_incomplete']);
|
|
49
51
|
|
|
50
52
|
/**
|
|
51
53
|
* Mask an API key for display (same shape the workspace backend uses for
|
|
@@ -295,7 +297,7 @@ class Daemon {
|
|
|
295
297
|
*/
|
|
296
298
|
_reprobeAfterRepair(agentType) {
|
|
297
299
|
const due = this.config.getAgents().filter((a) => (a.type || 'openclaw') === agentType
|
|
298
|
-
&& this._probes[a.name] && this._probes[a.name].code
|
|
300
|
+
&& this._probes[a.name] && REPROBE_AFTER_REPAIR.has(this._probes[a.name].code));
|
|
299
301
|
if (!due.length) return;
|
|
300
302
|
(async () => {
|
|
301
303
|
for (const a of due) {
|