@openagents-org/agent-launcher 0.2.226 → 0.2.228
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
CHANGED
package/src/adapters/codex.js
CHANGED
|
@@ -518,6 +518,18 @@ class CodexAdapter extends BaseAdapter {
|
|
|
518
518
|
await this._sendRunFailure(msgChannel, result, { partial: true });
|
|
519
519
|
}
|
|
520
520
|
return;
|
|
521
|
+
} else if (threadId && attempt === 0 && CodexAdapter._threadTooLarge(result)) {
|
|
522
|
+
// The thread holds an item the API will no longer take, and codex
|
|
523
|
+
// sends the whole thread with every turn, so every later message in
|
|
524
|
+
// this channel failed the same way. Only a new thread runs again.
|
|
525
|
+
this._log(`Thread ${threadId} for ${msgChannel} exceeds an API limit; starting a new one`);
|
|
526
|
+
delete this._channelThreads[msgChannel];
|
|
527
|
+
this._saveSessions();
|
|
528
|
+
try {
|
|
529
|
+
await this.sendStatus(msgChannel, 'This Codex conversation grew past what the model API accepts, '
|
|
530
|
+
+ 'so it continues in a new one. Earlier context in this thread is not carried over.');
|
|
531
|
+
} catch {}
|
|
532
|
+
continue;
|
|
521
533
|
} else if (result.exitCode !== 0 && threadId && attempt === 0 && !result.turnStarted && !CodexAdapter._serviceRefused(result)) {
|
|
522
534
|
// Stale thread — clear and retry fresh. Only when the turn never
|
|
523
535
|
// started: a thread codex cannot resume fails at once with nothing
|
|
@@ -814,6 +826,19 @@ class CodexAdapter extends BaseAdapter {
|
|
|
814
826
|
return Boolean(turnFailed) || (exitCode !== 0 && exitCode !== undefined);
|
|
815
827
|
}
|
|
816
828
|
|
|
829
|
+
/**
|
|
830
|
+
* True when the API refused the thread itself as too big. Seen as
|
|
831
|
+
* `[ArrayParam] [input[77].content] [array_above_max_length] Invalid
|
|
832
|
+
* 'input[77].content': array too long` on every message of one channel: an
|
|
833
|
+
* item in the history has more content parts than the API allows, and codex
|
|
834
|
+
* resends it each turn. The run's error, else what its stderr gives as the
|
|
835
|
+
* reason (_stderrReason), never a line of its log further up.
|
|
836
|
+
*/
|
|
837
|
+
static _threadTooLarge({ errorMessage, stderr } = {}) {
|
|
838
|
+
const reason = String(errorMessage || '').trim() || CodexAdapter._stderrReason(stderr);
|
|
839
|
+
return /array_above_max_length|context_length_exceeded/i.test(reason);
|
|
840
|
+
}
|
|
841
|
+
|
|
817
842
|
/**
|
|
818
843
|
* True when the model service turned the run away (rate limit, quota,
|
|
819
844
|
* credentials, network) — nothing to do with the thread being resumed. Such
|
package/src/adapters/opencode.js
CHANGED
|
@@ -27,6 +27,9 @@ const { buildOpenCodeSkillMd, buildOpenCodeSystemPrompt, workspaceSkillName } =
|
|
|
27
27
|
const { whichBinary, whereBinary, getEnhancedEnv } = require('../paths');
|
|
28
28
|
const { isPostinstallStub, isPostinstallStubOutput } = require('../postinstall-stub');
|
|
29
29
|
|
|
30
|
+
// The launcher's own CLI, whose `mcp-server` command serves the workspace tools.
|
|
31
|
+
const WORKSPACE_MCP_BIN = path.resolve(__dirname, '..', '..', 'bin', 'agent-connector.js');
|
|
32
|
+
|
|
30
33
|
const IS_WINDOWS = process.platform === 'win32';
|
|
31
34
|
|
|
32
35
|
// Max time an `opencode run` may stay completely silent. This is deliberately
|
|
@@ -68,6 +71,19 @@ const VERSION_PROBE_TTL_MS = 60000;
|
|
|
68
71
|
// provider keeps requests on `/chat/completions` and skips catalog validation.
|
|
69
72
|
const CUSTOM_PROVIDER_ID = 'openagents-gateway';
|
|
70
73
|
|
|
74
|
+
// The database OpenCode is pointed at (OPENCODE_DB) once the shared one cannot
|
|
75
|
+
// be opened. OpenCode 1.x and 2.x both default to <data>/opencode/opencode.db;
|
|
76
|
+
// 2.x renames the `session` table to `session_v2` when it migrates it, and from
|
|
77
|
+
// then on the 1.x CLI this adapter runs dies at startup with "Database is not
|
|
78
|
+
// empty and has no session table" on every message (opencode-ai 1.17.11,
|
|
79
|
+
// packages/core/src/database/migration.ts). OPENCODE_DB takes an absolute path
|
|
80
|
+
// in that version (packages/core/src/database/database.ts). Once this file
|
|
81
|
+
// exists it is used from then on; auth.json stays shared, so sign-ins keep
|
|
82
|
+
// working, and the user's own database is never written.
|
|
83
|
+
// Resolved per call, so it follows HOME.
|
|
84
|
+
const ownDbPath = () => path.join(os.homedir(), '.openagents', 'opencode', 'opencode.db');
|
|
85
|
+
const SHARED_DB_MIGRATED_RE = /database is not empty and has no session table/i;
|
|
86
|
+
|
|
71
87
|
// Short, de-identified, actionable user messages per failure category. These
|
|
72
88
|
// must NEVER default to "run auth login": only credential_missing / auth_failed
|
|
73
89
|
// mention authentication. Diagnostics (exit code, signal, redacted stdout/
|
|
@@ -94,6 +110,7 @@ const FAILURE_MESSAGES = {
|
|
|
94
110
|
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.',
|
|
95
111
|
process_crashed: 'OpenCode exited unexpectedly. Open diagnostics or retry.',
|
|
96
112
|
cwd_unavailable: "OpenCode's working directory is not accessible. Check the agent's configured path (or agent home) permissions.",
|
|
113
|
+
shared_db_migrated: "OpenCode could not open its session database: a newer OpenCode (2.x, or the OpenCode desktop app) on this device has converted it to a format the OpenCode CLI that OpenAgents runs cannot read, and running it on a database of its own did not help either. Reinstall OpenCode from the launcher, or set OPENCODE_DB in this agent's configuration to the full path of a new file, then retry.",
|
|
97
114
|
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.',
|
|
98
115
|
unknown_error: 'OpenCode failed for an undetermined reason. Open diagnostics or retry.',
|
|
99
116
|
};
|
|
@@ -252,8 +269,68 @@ class OpenCodeAdapter extends BaseAdapter {
|
|
|
252
269
|
touch();
|
|
253
270
|
return { touch, cancel, timeoutMs };
|
|
254
271
|
}
|
|
255
|
-
_spawnEnv() {
|
|
256
|
-
|
|
272
|
+
_spawnEnv(channel) {
|
|
273
|
+
const env = { ...(this.agentEnv || process.env) };
|
|
274
|
+
if (!env.OPENCODE_DB && fs.existsSync(ownDbPath())) env.OPENCODE_DB = ownDbPath();
|
|
275
|
+
if (!this._wiresWorkspaceMcp()) return env;
|
|
276
|
+
// Give OpenCode the workspace tools (publish, todos, browser, ...) through
|
|
277
|
+
// our MCP server, as the Claude adapter does. Merged into any inline config
|
|
278
|
+
// the host already passes; the token travels in the child's environment only.
|
|
279
|
+
let cfg = {};
|
|
280
|
+
try { cfg = JSON.parse(env.OPENCODE_CONFIG_CONTENT || '{}') || {}; } catch { return env; }
|
|
281
|
+
if (typeof cfg !== 'object' || Array.isArray(cfg)) return env;
|
|
282
|
+
const args = [WORKSPACE_MCP_BIN, 'mcp-server',
|
|
283
|
+
'--workspace-id', this.workspaceId, '--channel-name', channel || this.channelName || 'general',
|
|
284
|
+
'--agent-name', this.agentName, '--endpoint', this.endpoint];
|
|
285
|
+
const disabled = this.disabledModules || new Set();
|
|
286
|
+
if (disabled.has('files')) args.push('--disable-files');
|
|
287
|
+
if (disabled.has('browser')) args.push('--disable-browser');
|
|
288
|
+
if (disabled.has('knowledge')) args.push('--disable-knowledge');
|
|
289
|
+
const requester = channel && this.requesterEmailFor ? this.requesterEmailFor(channel) : null;
|
|
290
|
+
cfg.mcp = { ...(cfg.mcp || {}), openagents: { type: 'local', enabled: true,
|
|
291
|
+
command: [process.execPath, ...args],
|
|
292
|
+
environment: { OA_WORKSPACE_TOKEN: this.token, ...(requester ? { OPENAGENTS_REQUESTER_EMAIL: requester } : {}) } } };
|
|
293
|
+
env.OPENCODE_CONFIG_CONTENT = JSON.stringify(cfg);
|
|
294
|
+
return env;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Whether a run that failed on the shared database can be retried on
|
|
299
|
+
* ownDbPath(), creating that file if need be. False when the failed run was
|
|
300
|
+
* not on the shared database to begin with: OPENCODE_DB set by the user, the
|
|
301
|
+
* file already there before the run (`ownBefore`), or a fork that builds its
|
|
302
|
+
* own environment. The sessions saved so far are ids in the old database
|
|
303
|
+
* and are dropped when the file is created here.
|
|
304
|
+
*/
|
|
305
|
+
_moveToOwnDatabase(ownBefore) {
|
|
306
|
+
if (ownBefore || this._spawnEnv !== OpenCodeAdapter.prototype._spawnEnv) return false;
|
|
307
|
+
if ((this.agentEnv || process.env).OPENCODE_DB) return false;
|
|
308
|
+
const file = ownDbPath();
|
|
309
|
+
try {
|
|
310
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
311
|
+
fs.writeFileSync(file, '', { flag: 'wx' });
|
|
312
|
+
} catch (e) {
|
|
313
|
+
// Another channel's run got here first: the file is the one to use.
|
|
314
|
+
if (e && e.code === 'EEXIST') return true;
|
|
315
|
+
this._log(`Could not create ${file}: ${e && e.message}`, 'error');
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
this._log(`Shared OpenCode database was migrated by a newer OpenCode; using ${file}`);
|
|
319
|
+
this._channelSessions = {};
|
|
320
|
+
this._saveSessions();
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Only plain OpenCode reads OPENCODE_CONFIG_CONTENT; the forks built on this
|
|
326
|
+
* adapter (CodeArts, MiMo Code) replace _spawnEnv and keep the curl skill.
|
|
327
|
+
*/
|
|
328
|
+
_wiresWorkspaceMcp() {
|
|
329
|
+
// An OpenCode across the Windows/WSL boundary could not start our node.
|
|
330
|
+
const bin = String(this._opencodeBinary || '');
|
|
331
|
+
if (bin.startsWith('wsl:') || (!IS_WINDOWS && /\.(exe|cmd|bat)$/i.test(bin))) return false;
|
|
332
|
+
return this._spawnEnv === OpenCodeAdapter.prototype._spawnEnv
|
|
333
|
+
&& Boolean(this.token && this.workspaceId) && fs.existsSync(WORKSPACE_MCP_BIN);
|
|
257
334
|
}
|
|
258
335
|
|
|
259
336
|
/**
|
|
@@ -366,6 +443,7 @@ class OpenCodeAdapter extends BaseAdapter {
|
|
|
366
443
|
mode: this._mode,
|
|
367
444
|
model: this.modelLabel(),
|
|
368
445
|
disabledModules: this.disabledModules,
|
|
446
|
+
workspaceMcp: this._wiresWorkspaceMcp(),
|
|
369
447
|
...this.pinnedPromptOpts(channelName),
|
|
370
448
|
});
|
|
371
449
|
}
|
|
@@ -461,7 +539,16 @@ class OpenCodeAdapter extends BaseAdapter {
|
|
|
461
539
|
await this.sendStatus(msgChannel, 'thinking...');
|
|
462
540
|
|
|
463
541
|
try {
|
|
464
|
-
|
|
542
|
+
let responseText;
|
|
543
|
+
const ownBefore = fs.existsSync(ownDbPath());
|
|
544
|
+
try {
|
|
545
|
+
responseText = await this._runOpencode(content, msgChannel);
|
|
546
|
+
} catch (e) {
|
|
547
|
+
if (!(e && e.category === 'shared_db_migrated') || !this._moveToOwnDatabase(ownBefore)) throw e;
|
|
548
|
+
await this.sendStatus(msgChannel, "OpenCode's shared database was converted by a newer OpenCode on this "
|
|
549
|
+
+ 'device, so this agent now uses one of its own. Earlier context in this thread is not carried over.');
|
|
550
|
+
responseText = await this._runOpencode(content, msgChannel);
|
|
551
|
+
}
|
|
465
552
|
|
|
466
553
|
if (this._stoppingChannels.has(msgChannel)) {
|
|
467
554
|
this._stoppingChannels.delete(msgChannel);
|
|
@@ -1430,6 +1517,8 @@ class OpenCodeAdapter extends BaseAdapter {
|
|
|
1430
1517
|
let category;
|
|
1431
1518
|
if (isPostinstallStubOutput(hay)) {
|
|
1432
1519
|
category = 'install_incomplete';
|
|
1520
|
+
} else if (SHARED_DB_MIGRATED_RE.test(hay)) {
|
|
1521
|
+
category = 'shared_db_migrated';
|
|
1433
1522
|
} else if (configError) {
|
|
1434
1523
|
// Checked before the provider patterns: what is wrong with the file is
|
|
1435
1524
|
// free text ("Unrecognized key: model", "got {…401…}") that would read
|
|
@@ -978,15 +978,24 @@ function buildOpenclawSkillMd({ endpoint, workspaceId, token, agentName, channel
|
|
|
978
978
|
* `glossary` opts in to knowledge pinning exactly as in
|
|
979
979
|
* buildOpenclawSystemPrompt.
|
|
980
980
|
*/
|
|
981
|
-
function buildOpenCodeSystemPrompt({ agentName, workspaceId, channelName, endpoint, token, mode = 'execute', disabledModules, browserEnabled = false, glossary = null, isWindows = process.platform === 'win32', model = null }) {
|
|
982
|
-
|
|
981
|
+
function buildOpenCodeSystemPrompt({ agentName, workspaceId, channelName, endpoint, token, mode = 'execute', disabledModules, browserEnabled = false, glossary = null, isWindows = process.platform === 'win32', model = null, workspaceMcp = false }) {
|
|
982
|
+
// With the workspace MCP server wired in (see OpenCodeAdapter._spawnEnv) the
|
|
983
|
+
// agent gets real workspace_* tools, as Claude does; the curl skill stays on
|
|
984
|
+
// disk as a fallback. Without it, curl through OpenCode's shell tool, `bash`.
|
|
985
|
+
const toolMode = workspaceMcp ? 'mcp' : 'skills';
|
|
986
|
+
const skillName = workspaceSkillName(agentName);
|
|
987
|
+
const identity = buildWorkspaceIdentity(agentName, workspaceId, channelName, mode, toolMode, model);
|
|
983
988
|
const directive = buildBrowserDirective(browserEnabled);
|
|
984
|
-
const collab = buildCollaborationPrompt(
|
|
989
|
+
const collab = buildCollaborationPrompt(toolMode, skillName);
|
|
985
990
|
const modePrompt = buildModePrompt(mode) + buildWindowsShellHint(isWindows);
|
|
986
|
-
const pinned = buildPinnedSections({ toolMode
|
|
991
|
+
const pinned = buildPinnedSections({ toolMode, mode, glossary })
|
|
987
992
|
.map((s) => '\n' + s).join('');
|
|
988
|
-
const
|
|
989
|
-
|
|
993
|
+
const tools = workspaceMcp
|
|
994
|
+
? buildClaudeMcpToolBlock() +
|
|
995
|
+
'Use workspace_publish_project to share HTML pages or reports, workspace_write_file for other files, and the workspace_browser_* tools for the shared browser.\n' +
|
|
996
|
+
`If a workspace tool is missing or fails, the ${skillName} skill documents the same operations as bash + curl.\n`
|
|
997
|
+
: buildApiSkillsPrompt({ endpoint, workspaceId, token, agentName, channelName, disabledModules, mode, execTool: 'bash' });
|
|
998
|
+
return identity + directive + '\n' + collab + '\n' + modePrompt + pinned + '\n' + tools + '\n' + buildGuardrails();
|
|
990
999
|
}
|
|
991
1000
|
|
|
992
1001
|
/**
|
|
@@ -1005,7 +1014,7 @@ function buildPiSystemPrompt({ agentName, workspaceId, channelName, endpoint, to
|
|
|
1005
1014
|
const directive = buildBrowserDirective(browserEnabled);
|
|
1006
1015
|
const collab = buildCollaborationPrompt('skills', workspaceSkillName(agentName));
|
|
1007
1016
|
const modePrompt = buildModePrompt(mode);
|
|
1008
|
-
const api = buildApiSkillsPrompt({ endpoint, workspaceId, token, agentName, channelName, disabledModules, mode });
|
|
1017
|
+
const api = buildApiSkillsPrompt({ endpoint, workspaceId, token, agentName, channelName, disabledModules, mode, execTool: 'bash' });
|
|
1009
1018
|
return identity + directive + '\n' + collab + '\n' + modePrompt + '\n' + api + '\n' + buildGuardrails();
|
|
1010
1019
|
}
|
|
1011
1020
|
|
|
@@ -1149,6 +1158,7 @@ function buildOpenCodeSkillMd({ endpoint, workspaceId, token, agentName, channel
|
|
|
1149
1158
|
channelName: channelName || 'general',
|
|
1150
1159
|
disabledModules,
|
|
1151
1160
|
mode: 'execute',
|
|
1161
|
+
execTool: 'bash',
|
|
1152
1162
|
});
|
|
1153
1163
|
|
|
1154
1164
|
const frontmatter =
|