@openagents-org/agent-launcher 0.2.219 → 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/src/adapters/claude.js +13 -9
- package/src/adapters/codearts.js +1 -0
- package/src/adapters/codex.js +49 -9
- 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 +144 -23
- package/src/native-build.js +132 -0
- package/src/probe.js +64 -4
- package/src/utils.js +123 -12
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ws",
|
|
3
|
+
"version": "8.20.0",
|
|
4
|
+
"description": "Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"HyBi",
|
|
7
|
+
"Push",
|
|
8
|
+
"RFC-6455",
|
|
9
|
+
"WebSocket",
|
|
10
|
+
"WebSockets",
|
|
11
|
+
"real-time"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/websockets/ws",
|
|
14
|
+
"bugs": "https://github.com/websockets/ws/issues",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/websockets/ws.git"
|
|
18
|
+
},
|
|
19
|
+
"author": "Einar Otto Stangvik <einaros@gmail.com> (http://2x.io)",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"main": "index.js",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"browser": "./browser.js",
|
|
25
|
+
"import": "./wrapper.mjs",
|
|
26
|
+
"require": "./index.js"
|
|
27
|
+
},
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"browser": "browser.js",
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=10.0.0"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"browser.js",
|
|
36
|
+
"index.js",
|
|
37
|
+
"lib/*.js",
|
|
38
|
+
"wrapper.mjs"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"test": "nyc --reporter=lcov --reporter=text mocha --throw-deprecation test/*.test.js",
|
|
42
|
+
"integration": "mocha --throw-deprecation test/*.integration.js",
|
|
43
|
+
"lint": "eslint . && prettier --check --ignore-path .gitignore \"**/*.{json,md,yaml,yml}\""
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"bufferutil": "^4.0.1",
|
|
47
|
+
"utf-8-validate": ">=5.0.2"
|
|
48
|
+
},
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"bufferutil": {
|
|
51
|
+
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"utf-8-validate": {
|
|
54
|
+
"optional": true
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@eslint/js": "^10.0.1",
|
|
59
|
+
"benchmark": "^2.1.4",
|
|
60
|
+
"bufferutil": "^4.0.1",
|
|
61
|
+
"eslint": "^10.0.1",
|
|
62
|
+
"eslint-config-prettier": "^10.0.1",
|
|
63
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
64
|
+
"globals": "^17.0.0",
|
|
65
|
+
"mocha": "^8.4.0",
|
|
66
|
+
"nyc": "^15.0.0",
|
|
67
|
+
"prettier": "^3.0.0",
|
|
68
|
+
"utf-8-validate": "^6.0.0"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import createWebSocketStream from './lib/stream.js';
|
|
2
|
+
import extension from './lib/extension.js';
|
|
3
|
+
import PerMessageDeflate from './lib/permessage-deflate.js';
|
|
4
|
+
import Receiver from './lib/receiver.js';
|
|
5
|
+
import Sender from './lib/sender.js';
|
|
6
|
+
import subprotocol from './lib/subprotocol.js';
|
|
7
|
+
import WebSocket from './lib/websocket.js';
|
|
8
|
+
import WebSocketServer from './lib/websocket-server.js';
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
createWebSocketStream,
|
|
12
|
+
extension,
|
|
13
|
+
PerMessageDeflate,
|
|
14
|
+
Receiver,
|
|
15
|
+
Sender,
|
|
16
|
+
subprotocol,
|
|
17
|
+
WebSocket,
|
|
18
|
+
WebSocketServer
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default WebSocket;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openagents-org/agent-launcher",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.220",
|
|
4
4
|
"description": "OpenAgents Launcher — install, configure, and run AI coding agents from your terminal",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -42,5 +42,8 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"blessed": "^0.1.81",
|
|
44
44
|
"ws": "^8.18.0"
|
|
45
|
-
}
|
|
45
|
+
},
|
|
46
|
+
"bundleDependencies": [
|
|
47
|
+
"ws"
|
|
48
|
+
]
|
|
46
49
|
}
|
package/src/adapters/claude.js
CHANGED
|
@@ -1603,15 +1603,19 @@ class ClaudeAdapter extends BaseAdapter {
|
|
|
1603
1603
|
|
|
1604
1604
|
/**
|
|
1605
1605
|
* @anthropic-ai/claude-code ships a placeholder where its native binary goes
|
|
1606
|
-
* and swaps the real one in from a postinstall script
|
|
1607
|
-
*
|
|
1608
|
-
*
|
|
1609
|
-
*
|
|
1606
|
+
* and swaps the real one in from a postinstall script, copied out of a
|
|
1607
|
+
* per-platform optional dependency. Skip that script (`ignore-scripts=true` in
|
|
1608
|
+
* an npmrc, pnpm, bun) or lose that dependency (npm drops one whose download
|
|
1609
|
+
* fails, or under omit=optional) and the placeholder is what runs: shell text
|
|
1610
|
+
* on macOS/Linux, and on Windows a `claude.exe` the OS will not start (spawn
|
|
1611
|
+
* EFTYPE). Which of the two happened is the installer's to find out; a
|
|
1612
|
+
* reinstall from the launcher handles both (installer.finishNpmInstall).
|
|
1610
1613
|
*/
|
|
1611
|
-
ClaudeAdapter.INSTALL_INCOMPLETE = 'Claude Code is installed, but its setup never finished
|
|
1612
|
-
+ '@anthropic-ai/claude-code package\'s postinstall
|
|
1613
|
-
+ '
|
|
1614
|
-
+ '
|
|
1615
|
-
+ '
|
|
1614
|
+
ClaudeAdapter.INSTALL_INCOMPLETE = 'Claude Code is installed, but its setup never finished, so the '
|
|
1615
|
+
+ '`claude` command is only a placeholder: either the @anthropic-ai/claude-code package\'s postinstall '
|
|
1616
|
+
+ 'script did not run (npm `ignore-scripts`, or a pnpm/bun install), or npm left out the per-platform '
|
|
1617
|
+
+ 'package that holds the native binary (its download failed, or optional dependencies are turned off). '
|
|
1618
|
+
+ 'Reinstall Claude Code from the launcher — or, for a copy you installed yourself, run '
|
|
1619
|
+
+ '`npm install -g @anthropic-ai/claude-code --ignore-scripts=false --include=optional` — then retry.';
|
|
1616
1620
|
|
|
1617
1621
|
module.exports = ClaudeAdapter;
|
package/src/adapters/codearts.js
CHANGED
|
@@ -79,6 +79,7 @@ const FAILURE_MESSAGES = {
|
|
|
79
79
|
incomplete_run: 'CodeArts Agent stopped mid-task right after a tool call and never produced a final reply — its progress notes are shown above. Send "continue" to pick up where it left off.',
|
|
80
80
|
process_crashed: 'CodeArts Agent exited unexpectedly. Open diagnostics or retry.',
|
|
81
81
|
cwd_unavailable: "CodeArts Agent's working directory is not accessible. Check the agent's configured path (or agent home) permissions.",
|
|
82
|
+
config_invalid: 'CodeArts Agent 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.',
|
|
82
83
|
unknown_error: 'CodeArts Agent failed for an undetermined reason. Open diagnostics or retry.',
|
|
83
84
|
};
|
|
84
85
|
|
package/src/adapters/codex.js
CHANGED
|
@@ -63,6 +63,12 @@ const CODEX_LOG_RECORD = /^\d{4}-\d{2}-\d{2}T[\d:.]+Z?\s+(TRACE|DEBUG|INFO|WARN|
|
|
|
63
63
|
// Things codex says beside a run rather than about it, such as a config key
|
|
64
64
|
// it skipped. Quoted only when nothing else was said.
|
|
65
65
|
const CODEX_SIDE_NOTE = /^warning:/i;
|
|
66
|
+
// ERROR records codex logs beside a run, not about it: a skill file it could
|
|
67
|
+
// not parse (it skips that skill and answers anyway, verified with codex-cli
|
|
68
|
+
// 0.167), and its own ChatGPT connector (rmcp) losing a side connection. In
|
|
69
|
+
// the field they came first in stderr and were quoted as the reason a run
|
|
70
|
+
// failed. Quoted only when nothing else was logged.
|
|
71
|
+
const CODEX_SIDE_ERROR = /\brmcp::|failed to load skill\b/;
|
|
66
72
|
// Codex's wording when the model service could not be reached or the stream
|
|
67
73
|
// dropped. Seen in the field from devices that cannot reach OpenAI, and
|
|
68
74
|
// reproduced against codex-cli 0.160 behind a dead proxy: the run then fails
|
|
@@ -71,6 +77,13 @@ const CODEX_SIDE_NOTE = /^warning:/i;
|
|
|
71
77
|
const CODEX_CONNECTION_FAILURE = /error sending request|Connection failed|failed to connect to websocket: IO error|tls handshake|dns error|failed to lookup address|stream disconnected before completion|workspace routing discovery (?:failed|timed out)|request timed out/i;
|
|
72
78
|
// codex retrying a failed connection by itself: "Reconnecting... 2/5 (why)".
|
|
73
79
|
const CODEX_RECONNECTING = /^Reconnecting\.\.\.\s*\d+\/\d+\s*(?:\((.*)\))?\s*$/i;
|
|
80
|
+
// An endpoint refusing a field of the request. Codex sends the same fields
|
|
81
|
+
// (client_metadata among them) on every turn and has no setting to drop one,
|
|
82
|
+
// so on a custom Responses provider this fails every run.
|
|
83
|
+
const PARAM_REFUSED = /unsupported .{0,40}parameter|unsupported_parameter|unknown parameter|unrecognized request argument|unrecognized (key|field)|additional properties|extra (inputs|fields) are not permitted/i;
|
|
84
|
+
// OpenAI's own "Unsupported parameter: 'reasoning.effort' is not supported with
|
|
85
|
+
// this model" is about the model chosen, which the user can change.
|
|
86
|
+
const MODEL_CAPABILITY_REFUSAL = /with this model|reasoning[._]/i;
|
|
74
87
|
// The service answered and said no: a key, a plan, a quota, or a model it
|
|
75
88
|
// will not serve. Network advice would send the user the wrong way. The
|
|
76
89
|
// terms of _serviceRefused, less "error sending request" (that one is a
|
|
@@ -777,7 +790,7 @@ class CodexAdapter extends BaseAdapter {
|
|
|
777
790
|
* reply, instead of a generic "No response generated".
|
|
778
791
|
*/
|
|
779
792
|
async _sendRunFailure(msgChannel, result, { partial = false } = {}) {
|
|
780
|
-
const detail = CodexAdapter._failureDetail(result);
|
|
793
|
+
const detail = CodexAdapter._failureDetail(result, { customProvider: this._customProvider });
|
|
781
794
|
if (partial) {
|
|
782
795
|
const body = detail
|
|
783
796
|
? `It stopped before finishing this task.\n\n> ${detail}`
|
|
@@ -825,13 +838,19 @@ class CodexAdapter extends BaseAdapter {
|
|
|
825
838
|
* The cap applies to the quoted reason, before the advice is added, so a
|
|
826
839
|
* long stderr cannot push the advice out of the message.
|
|
827
840
|
*/
|
|
828
|
-
static _failureDetail({ errorMessage, stderr, exitCode, signal } = {}) {
|
|
841
|
+
static _failureDetail({ errorMessage, stderr, exitCode, signal } = {}, { customProvider = null } = {}) {
|
|
842
|
+
// A clean exit with no turn.failed and no error event is codex saying the
|
|
843
|
+
// turn finished; it just wrote no reply. Whatever stderr holds then is not
|
|
844
|
+
// why (a skill it skipped, its ChatGPT connector), and quoting it read as
|
|
845
|
+
// "failed to complete this run > failed to load skill …" for a run that
|
|
846
|
+
// had not failed.
|
|
847
|
+
const finished = exitCode === 0 && !signal;
|
|
829
848
|
const raw = String(errorMessage || '').trim()
|
|
830
|
-
|| CodexAdapter._stderrReason(stderr)
|
|
849
|
+
|| (finished ? '' : CodexAdapter._stderrReason(stderr))
|
|
831
850
|
|| (signal ? `codex was terminated by ${signal}` : '')
|
|
832
851
|
|| (exitCode ? `codex exited with code ${exitCode}` : '');
|
|
833
852
|
const reason = CodexAdapter._redact(CodexAdapter._unwrap(raw)).slice(0, FAILURE_DETAIL_CAP).trim();
|
|
834
|
-
return reason ? CodexAdapter._explain(reason, stderr) : '';
|
|
853
|
+
return reason ? CodexAdapter._explain(reason, stderr, { customProvider }) : '';
|
|
835
854
|
}
|
|
836
855
|
|
|
837
856
|
/**
|
|
@@ -854,7 +873,8 @@ class CodexAdapter extends BaseAdapter {
|
|
|
854
873
|
* (or "Reading additional input from stdin...") on every run. A plain tail
|
|
855
874
|
* of the last lines was mostly that noise. So, in order: lines the CLI
|
|
856
875
|
* printed for a person; failing those, its ERROR records with timestamp and
|
|
857
|
-
* module stripped; failing those, its warnings
|
|
876
|
+
* module stripped; failing those, its warnings and the ERROR records it logs
|
|
877
|
+
* beside a run (CODEX_SIDE_ERROR). The banner and known-harmless
|
|
858
878
|
* lines are never a reason: a clean exit with only the banner reads as "no
|
|
859
879
|
* reply", not as "> Reading prompt from stdin...".
|
|
860
880
|
*
|
|
@@ -871,7 +891,8 @@ class CodexAdapter extends BaseAdapter {
|
|
|
871
891
|
const record = CODEX_LOG_RECORD.exec(line);
|
|
872
892
|
if (record) {
|
|
873
893
|
const [, level, message] = record;
|
|
874
|
-
const
|
|
894
|
+
const side = level === 'WARN' || (level === 'ERROR' && CODEX_SIDE_ERROR.test(line));
|
|
895
|
+
const bucket = side ? notes : level === 'ERROR' ? errors : null;
|
|
875
896
|
if (bucket && message && !bucket.includes(message)) bucket.push(message);
|
|
876
897
|
} else if (!BENIGN_CLI_OUTPUT.test(line)) {
|
|
877
898
|
(CODEX_SIDE_NOTE.test(line) ? notes : said).push(line);
|
|
@@ -896,8 +917,14 @@ class CodexAdapter extends BaseAdapter {
|
|
|
896
917
|
for (const key of ['detail', 'message', 'error']) {
|
|
897
918
|
const v = parsed && parsed[key];
|
|
898
919
|
if (typeof v === 'string' && v.trim()) return v.trim();
|
|
899
|
-
// OpenAI also nests as { error: { message } }.
|
|
900
|
-
|
|
920
|
+
// OpenAI also nests as { error: { message } }. Its `param` names the
|
|
921
|
+
// field a 400 is about — "Unsupported Responses request parameter."
|
|
922
|
+
// alone did not say which.
|
|
923
|
+
if (v && typeof v.message === 'string' && v.message.trim()) {
|
|
924
|
+
const message = v.message.trim();
|
|
925
|
+
const param = typeof v.param === 'string' ? v.param.trim() : '';
|
|
926
|
+
return param && !message.includes(param) ? `${message} (parameter: ${param})` : message;
|
|
927
|
+
}
|
|
901
928
|
}
|
|
902
929
|
} catch {}
|
|
903
930
|
return text;
|
|
@@ -912,7 +939,20 @@ class CodexAdapter extends BaseAdapter {
|
|
|
912
939
|
* match is on the backend's own wording, so an unrelated failure is passed
|
|
913
940
|
* through untouched.
|
|
914
941
|
*/
|
|
915
|
-
static _explain(detail, stderr = '') {
|
|
942
|
+
static _explain(detail, stderr = '', { customProvider = null } = {}) {
|
|
943
|
+
// A custom Responses endpoint refusing a field Codex always sends. Nothing
|
|
944
|
+
// the user retries changes that; which endpoint to use, or the chat-only
|
|
945
|
+
// mode, does.
|
|
946
|
+
if (customProvider && PARAM_REFUSED.test(detail) && !MODEL_CAPABILITY_REFUSAL.test(detail)) {
|
|
947
|
+
let host = '';
|
|
948
|
+
try { host = new URL(customProvider.baseUrl).host; } catch {}
|
|
949
|
+
const m = /\(parameter: ([^)]+)\)/.exec(detail) || /parameter:?\s*'([\w.[\]]+)'/i.exec(detail);
|
|
950
|
+
return `${detail}\n\nThe endpoint this agent is set to${host ? ` (${host})` : ''} takes Responses API requests ` +
|
|
951
|
+
`but refuses ${m ? `the "${m[1]}" field` : 'a field'} that the Codex CLI sends with every one of them, ` +
|
|
952
|
+
'and Codex has no setting to leave it out — so every run here will fail the same way. Point the agent ' +
|
|
953
|
+
'at an endpoint that supports the full Responses API, or edit the agent and set Agent capabilities to ' +
|
|
954
|
+
'"Chat only · Chat Completions API" (it then answers without running tools on this device).';
|
|
955
|
+
}
|
|
916
956
|
// Ahead of the network check: a model that needs a newer Codex can
|
|
917
957
|
// arrive with connection warnings in stderr, and the upgrade is the fix.
|
|
918
958
|
if (/requires a newer version|upgrade to the latest (app|version)/i.test(detail)) {
|
|
@@ -297,6 +297,71 @@ function encodeKimiWorkDirKey(workDir) {
|
|
|
297
297
|
return `wd_${slug}_${hash}`;
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
+
// ---------------------------------------------------------------------------
|
|
301
|
+
// What a session journal says is still running
|
|
302
|
+
// ---------------------------------------------------------------------------
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Follows a session journal (`agents/main/wire.jsonl`) as it grows and keeps
|
|
306
|
+
* the tool calls and background tasks it shows as started but not finished.
|
|
307
|
+
*
|
|
308
|
+
* Print mode says nothing while a tool runs — not even the tool call, which
|
|
309
|
+
* only comes out with its result — but the journal records each step as it
|
|
310
|
+
* happens (verified v2.5.2):
|
|
311
|
+
* {type:"context.append_loop_event", event:{type:"step.begin"}} a model step starts
|
|
312
|
+
* {type:"context.append_loop_event", event:{type:"tool.call", toolCallId}} a tool starts
|
|
313
|
+
* {type:"context.append_loop_event", event:{type:"tool.result", toolCallId}} it ends
|
|
314
|
+
* {type:"task.started", info:{taskId}} / {type:"task.terminated", info:{taskId}}
|
|
315
|
+
* a background task (Bash run_in_background), which the run waits on
|
|
316
|
+
* Every record carries `time`, ms since the epoch. Kimi bounds both itself: a
|
|
317
|
+
* foreground command at 300s, a task at its timeoutMs.
|
|
318
|
+
*
|
|
319
|
+
* A record from before `since` (the run's start) opens nothing: it belongs to
|
|
320
|
+
* an earlier run, maybe one that was stopped mid-tool. A step begins only
|
|
321
|
+
* after the previous step's tools have returned, so `step.begin` closes any
|
|
322
|
+
* call still open — as does `turn.ended`; a task outlives both. Lines it does
|
|
323
|
+
* not know are skipped. A journal whose shape changed reads as "nothing
|
|
324
|
+
* running", or — if starts are still recognized and ends are not — as a
|
|
325
|
+
* tool running until the next step: never as a reason to stop a run earlier.
|
|
326
|
+
*/
|
|
327
|
+
class KimiWireTracker {
|
|
328
|
+
constructor({ since = 0 } = {}) {
|
|
329
|
+
this._since = since;
|
|
330
|
+
this._partial = '';
|
|
331
|
+
this.toolCalls = new Set();
|
|
332
|
+
this.tasks = new Set();
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** Feed the next chunk of the file. */
|
|
336
|
+
push(chunk) {
|
|
337
|
+
const lines = (this._partial + chunk).split('\n');
|
|
338
|
+
this._partial = lines.pop();
|
|
339
|
+
for (const line of lines) {
|
|
340
|
+
let e;
|
|
341
|
+
try { e = JSON.parse(line); } catch { continue; }
|
|
342
|
+
if (!e || typeof e !== 'object') continue;
|
|
343
|
+
const current = !(typeof e.time === 'number' && e.time < this._since);
|
|
344
|
+
const ev = e.event && typeof e.event === 'object' ? e.event : null;
|
|
345
|
+
if (e.type === 'context.append_loop_event' && ev && ev.type === 'step.begin') {
|
|
346
|
+
this.toolCalls.clear();
|
|
347
|
+
} else if (e.type === 'context.append_loop_event' && ev && typeof ev.toolCallId === 'string') {
|
|
348
|
+
if (ev.type === 'tool.call' && current) this.toolCalls.add(ev.toolCallId);
|
|
349
|
+
else if (ev.type === 'tool.result') this.toolCalls.delete(ev.toolCallId);
|
|
350
|
+
} else if ((e.type === 'task.started' || e.type === 'task.terminated') && e.info && typeof e.info.taskId === 'string') {
|
|
351
|
+
if (e.type === 'task.started') { if (current) this.tasks.add(e.info.taskId); }
|
|
352
|
+
else this.tasks.delete(e.info.taskId);
|
|
353
|
+
} else if (e.type === 'turn.ended') {
|
|
354
|
+
this.toolCalls.clear();
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** Whether a tool call or a background task is still running. */
|
|
360
|
+
get busy() {
|
|
361
|
+
return this.toolCalls.size > 0 || this.tasks.size > 0;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
300
365
|
// ---------------------------------------------------------------------------
|
|
301
366
|
// Error classification
|
|
302
367
|
// ---------------------------------------------------------------------------
|
|
@@ -319,24 +384,31 @@ function extractStderrError(stderrText) {
|
|
|
319
384
|
|
|
320
385
|
/**
|
|
321
386
|
* Classify a failed run into a user-facing message.
|
|
322
|
-
* @param {{code: number|null, signal: string|null, stderrText: string, retryMessage: string, timedOutMs?: number}} info
|
|
387
|
+
* @param {{code: number|null, signal: string|null, stderrText: string, retryMessage: string, timedOutMs?: number, timedOutInTool?: boolean}} info
|
|
323
388
|
* `timedOutMs` is set when the adapter's idle watchdog stopped the run after
|
|
324
|
-
* that long without any sign of progress
|
|
389
|
+
* that long without any sign of progress; `timedOutInTool` when a tool call
|
|
390
|
+
* or background task was still running then (see KimiWireTracker).
|
|
325
391
|
* @returns {{kind: string, userMessage: string}}
|
|
326
392
|
*/
|
|
327
393
|
function classifyKimiError(info) {
|
|
328
|
-
const { code, signal, stderrText, retryMessage, timedOutMs } = info || {};
|
|
394
|
+
const { code, signal, stderrText, retryMessage, timedOutMs, timedOutInTool } = info || {};
|
|
329
395
|
const detail = extractStderrError(stderrText) || redactSecrets(retryMessage || '');
|
|
330
396
|
|
|
331
397
|
// The watchdog's own stop wins: the signal it leaves behind (SIGINT on
|
|
332
398
|
// Windows) explains nothing, and stderr by then holds whatever tools printed.
|
|
399
|
+
// "No progress" read as a hang; in print mode Kimi says nothing while the
|
|
400
|
+
// model works on a step, so the message says what was actually seen.
|
|
333
401
|
if (timedOutMs) {
|
|
334
402
|
const minutes = Math.max(1, Math.round(timedOutMs / 60000));
|
|
335
403
|
return {
|
|
336
404
|
kind: 'timeout',
|
|
337
405
|
userMessage:
|
|
338
|
-
|
|
339
|
-
|
|
406
|
+
(timedOutInTool
|
|
407
|
+
? `A command or task Kimi started was still running after about ${minutes} min with no output, so Kimi was stopped. ` +
|
|
408
|
+
'Send the request again, or ask Kimi to split the long command into smaller parts.'
|
|
409
|
+
: `Kimi printed nothing for about ${minutes} min and was stopped. Kimi prints nothing while the model ` +
|
|
410
|
+
'works on a step, so a very long step looks the same as a stuck one. ' +
|
|
411
|
+
'Send the request again, or break a long task into smaller steps.') +
|
|
340
412
|
(detail ? `\n\nDetails: ${detail}` : ''),
|
|
341
413
|
};
|
|
342
414
|
}
|
|
@@ -457,6 +529,7 @@ module.exports = {
|
|
|
457
529
|
buildKimiArgs,
|
|
458
530
|
buildKimiEnv,
|
|
459
531
|
encodeKimiWorkDirKey,
|
|
532
|
+
KimiWireTracker,
|
|
460
533
|
extractStderrError,
|
|
461
534
|
classifyKimiError,
|
|
462
535
|
DEFAULT_KIMI_MODEL,
|
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
|
|