@elvatis_com/openclaw-cli-bridge-elvatis 3.5.0 → 3.6.0
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/README.md +1 -1
- package/SKILL.md +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/src/cli-runner.ts +116 -2
- package/src/proxy-server.ts +12 -5
- package/src/tool-protocol.ts +50 -28
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> OpenClaw plugin that bridges locally installed AI CLIs (Codex, Gemini, Claude Code, OpenCode, Pi) as model providers — with slash commands for instant model switching, restore, health testing, and model listing.
|
|
4
4
|
|
|
5
|
-
**Current version:** `3.
|
|
5
|
+
**Current version:** `3.6.0`
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
package/SKILL.md
CHANGED
package/openclaw.plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "openclaw-cli-bridge-elvatis",
|
|
3
3
|
"slug": "openclaw-cli-bridge-elvatis",
|
|
4
4
|
"name": "OpenClaw CLI Bridge",
|
|
5
|
-
"version": "3.
|
|
5
|
+
"version": "3.6.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "Phase 1: openai-codex auth bridge. Phase 2: local HTTP proxy routing model calls through gemini/claude CLIs (vllm provider).",
|
|
8
8
|
"providers": [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elvatis_com/openclaw-cli-bridge-elvatis",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "Bridges gemini, claude, and codex CLI tools as OpenClaw model providers. Reads existing CLI auth without re-login.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"openclaw": {
|
package/src/cli-runner.ts
CHANGED
|
@@ -1003,6 +1003,108 @@ function detectProjectFromPrompt(prompt: string): { name: string; path: string }
|
|
|
1003
1003
|
return null;
|
|
1004
1004
|
}
|
|
1005
1005
|
|
|
1006
|
+
// ── Skill hint injection ─────────────────────────────────────────────────────
|
|
1007
|
+
// Scans ~/.openclaw/skills/ for skill directories with SKILL.md files.
|
|
1008
|
+
// When user prompt mentions a skill name (from the directory name or the SKILL.md
|
|
1009
|
+
// description), injects a pointer so the model knows where to find it.
|
|
1010
|
+
|
|
1011
|
+
interface SkillEntry {
|
|
1012
|
+
name: string;
|
|
1013
|
+
path: string;
|
|
1014
|
+
description: string;
|
|
1015
|
+
keywords: string[];
|
|
1016
|
+
scripts: string[];
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
let _skillRegistry: SkillEntry[] | null = null;
|
|
1020
|
+
let _skillRegistryRefreshedAt = 0;
|
|
1021
|
+
const SKILL_REGISTRY_CACHE_TTL = 120_000; // refresh every 2 min
|
|
1022
|
+
|
|
1023
|
+
function getSkillRegistry(): SkillEntry[] {
|
|
1024
|
+
const now = Date.now();
|
|
1025
|
+
if (_skillRegistry && (now - _skillRegistryRefreshedAt) < SKILL_REGISTRY_CACHE_TTL) {
|
|
1026
|
+
return _skillRegistry;
|
|
1027
|
+
}
|
|
1028
|
+
_skillRegistry = [];
|
|
1029
|
+
const skillsDir = join(homedir(), ".openclaw", "skills");
|
|
1030
|
+
try {
|
|
1031
|
+
if (!existsSync(skillsDir)) return _skillRegistry;
|
|
1032
|
+
const entries = readdirSync(skillsDir);
|
|
1033
|
+
for (const name of entries) {
|
|
1034
|
+
const skillDir = join(skillsDir, name);
|
|
1035
|
+
const skillMd = join(skillDir, "SKILL.md");
|
|
1036
|
+
try {
|
|
1037
|
+
if (!statSync(skillDir).isDirectory()) continue;
|
|
1038
|
+
if (!existsSync(skillMd)) continue;
|
|
1039
|
+
// Read first 500 chars of SKILL.md to extract description and keywords
|
|
1040
|
+
const content = readFileSync(skillMd, "utf8").slice(0, 500);
|
|
1041
|
+
const descMatch = content.match(/description:\s*"([^"]+)"/);
|
|
1042
|
+
const description = descMatch?.[1] ?? "";
|
|
1043
|
+
// Build keywords from: skill name, words in description, hyphen-split name parts
|
|
1044
|
+
const keywords = [
|
|
1045
|
+
name,
|
|
1046
|
+
...name.split("-"),
|
|
1047
|
+
...description.toLowerCase().split(/[\s,.:;]+/).filter(w => w.length > 3),
|
|
1048
|
+
];
|
|
1049
|
+
// Find scripts
|
|
1050
|
+
const scriptsDir = join(skillDir, "scripts");
|
|
1051
|
+
let scripts: string[] = [];
|
|
1052
|
+
try {
|
|
1053
|
+
if (existsSync(scriptsDir) && statSync(scriptsDir).isDirectory()) {
|
|
1054
|
+
scripts = readdirSync(scriptsDir).filter(f => f.endsWith(".py") || f.endsWith(".sh"));
|
|
1055
|
+
}
|
|
1056
|
+
} catch { /* no scripts dir */ }
|
|
1057
|
+
_skillRegistry.push({ name, path: skillDir, description, keywords, scripts });
|
|
1058
|
+
} catch { /* skip unreadable skill */ }
|
|
1059
|
+
}
|
|
1060
|
+
} catch { /* no skills dir */ }
|
|
1061
|
+
_skillRegistryRefreshedAt = now;
|
|
1062
|
+
return _skillRegistry;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
function detectSkillHints(userText: string): string | null {
|
|
1066
|
+
const skills = getSkillRegistry();
|
|
1067
|
+
if (!skills.length) return null;
|
|
1068
|
+
|
|
1069
|
+
const lower = userText.toLowerCase();
|
|
1070
|
+
const matched: SkillEntry[] = [];
|
|
1071
|
+
|
|
1072
|
+
for (const skill of skills) {
|
|
1073
|
+
// Match by exact skill name in prompt
|
|
1074
|
+
const nameRegex = new RegExp(`\\b${skill.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`, "i");
|
|
1075
|
+
if (nameRegex.test(userText)) {
|
|
1076
|
+
matched.push(skill);
|
|
1077
|
+
continue;
|
|
1078
|
+
}
|
|
1079
|
+
// Match by description keywords (need at least 2 keyword hits)
|
|
1080
|
+
const uniqueKeywords = [...new Set(skill.keywords)];
|
|
1081
|
+
const hits = uniqueKeywords.filter(kw => lower.includes(kw.toLowerCase()));
|
|
1082
|
+
if (hits.length >= 2) {
|
|
1083
|
+
matched.push(skill);
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
if (!matched.length) return null;
|
|
1088
|
+
|
|
1089
|
+
const hints = matched.map(skill => {
|
|
1090
|
+
const lines = [
|
|
1091
|
+
`[Skill: ${skill.name}]`,
|
|
1092
|
+
`Read the skill instructions with the read tool: ${skill.path}/SKILL.md`,
|
|
1093
|
+
`Then follow the workflow step by step using the available tools (read, exec, web_fetch, etc.).`,
|
|
1094
|
+
];
|
|
1095
|
+
if (skill.scripts.length > 0) {
|
|
1096
|
+
lines.push(`Available scripts (use exec tool to run them):`);
|
|
1097
|
+
for (const s of skill.scripts) {
|
|
1098
|
+
lines.push(` - python3 ${skill.path}/scripts/${s}`);
|
|
1099
|
+
}
|
|
1100
|
+
lines.push(`Always use exec to run scripts. Do NOT output results as plain text when a script can do it.`);
|
|
1101
|
+
}
|
|
1102
|
+
return lines.join("\n");
|
|
1103
|
+
});
|
|
1104
|
+
|
|
1105
|
+
return hints.join("\n\n");
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1006
1108
|
/**
|
|
1007
1109
|
* Route a chat completion to the correct CLI based on model prefix.
|
|
1008
1110
|
* cli-gemini/<id> → gemini CLI
|
|
@@ -1027,9 +1129,14 @@ export async function routeToCliRunner(
|
|
|
1027
1129
|
let prompt = formatPrompt(messages, toolCount);
|
|
1028
1130
|
const hasTools = toolCount > 0;
|
|
1029
1131
|
|
|
1030
|
-
// Auto-detect project from
|
|
1132
|
+
// Auto-detect project from user messages only (not tool results which mention other projects)
|
|
1133
|
+
const userText = messages
|
|
1134
|
+
.filter((m) => m.role === "user")
|
|
1135
|
+
.map((m) => typeof m.content === "string" ? m.content : "")
|
|
1136
|
+
.join(" ");
|
|
1137
|
+
|
|
1031
1138
|
if (!opts.workdir) {
|
|
1032
|
-
const detected = detectProjectFromPrompt(
|
|
1139
|
+
const detected = detectProjectFromPrompt(userText);
|
|
1033
1140
|
if (detected) {
|
|
1034
1141
|
opts = { ...opts, workdir: detected.path };
|
|
1035
1142
|
prompt = `[Context: Working directory is ${detected.path}]\n\n${prompt}`;
|
|
@@ -1037,6 +1144,13 @@ export async function routeToCliRunner(
|
|
|
1037
1144
|
}
|
|
1038
1145
|
}
|
|
1039
1146
|
|
|
1147
|
+
// Skill hints: inject pointers to local skill files when user prompt matches known patterns
|
|
1148
|
+
const skillHints = detectSkillHints(userText);
|
|
1149
|
+
if (skillHints) {
|
|
1150
|
+
prompt = `${skillHints}\n\n${prompt}`;
|
|
1151
|
+
debugLog("SKILL-HINT", "injected skill hints", { len: skillHints.length });
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1040
1154
|
// Strip "vllm/" prefix if present — OpenClaw sends the full provider path
|
|
1041
1155
|
// (e.g. "vllm/cli-claude/claude-sonnet-4-6") but the router only needs the
|
|
1042
1156
|
// "cli-<type>/<model>" portion.
|
package/src/proxy-server.ts
CHANGED
|
@@ -448,6 +448,9 @@ async function handleRequest(
|
|
|
448
448
|
const promptPreview = typeof lastUserMsg?.content === "string" ? lastUserMsg.content.slice(0, 80) : "";
|
|
449
449
|
|
|
450
450
|
debugLog("REQ", `${model} start`, { msgs: cleanMessages.length, tools: tools?.length ?? 0, stream, media: mediaFiles.length, promptPreview: promptPreview.slice(0, 60) });
|
|
451
|
+
if (hasTools && tools!.length > 0) {
|
|
452
|
+
debugLog("TOOLS", `${tools!.length} tools available`, { names: tools!.map(t => t.function?.name ?? t.name ?? "?").join(", ") });
|
|
453
|
+
}
|
|
451
454
|
|
|
452
455
|
// Track active request for dashboard
|
|
453
456
|
activeRequests.set(id, { id, model, startedAt: Date.now(), messageCount: cleanMessages.length, toolCount: tools?.length ?? 0, promptPreview });
|
|
@@ -939,7 +942,14 @@ async function handleRequest(
|
|
|
939
942
|
opts.warn(`[cli-bridge] ${model} failed (${reason}), trying fallback chain: ${fallbackChain.join(" → ")}`);
|
|
940
943
|
|
|
941
944
|
let chainSuccess = false;
|
|
945
|
+
const lastMsg = cleanMessages[cleanMessages.length - 1];
|
|
946
|
+
const inToolLoop = hasTools && (lastMsg?.role === "tool" || lastMsg?.role === "function");
|
|
942
947
|
for (const fallbackModel of fallbackChain) {
|
|
948
|
+
// Skip Haiku in tool loops — it consistently returns text instead of tool_calls, wasting ~8-12s
|
|
949
|
+
if (inToolLoop && fallbackModel.includes("haiku")) {
|
|
950
|
+
debugLog("FALLBACK-SKIP", `skipping ${fallbackModel} in tool loop (unreliable for tool_calls)`, {});
|
|
951
|
+
continue;
|
|
952
|
+
}
|
|
943
953
|
debugLog("FALLBACK", `${model} → ${fallbackModel}`, { reason: isTimeout ? "timeout" : "error", primaryDuration: Math.round(primaryDuration / 1000), chain: fallbackChain });
|
|
944
954
|
if (sseHeadersSent) {
|
|
945
955
|
res.write(`: fallback — trying ${fallbackModel}\n\n`);
|
|
@@ -952,12 +962,9 @@ async function handleRequest(
|
|
|
952
962
|
debugLog("FALLBACK-EMPTY", `${fallbackModel} returned empty`, {});
|
|
953
963
|
throw new Error(`empty response from ${fallbackModel}`);
|
|
954
964
|
}
|
|
955
|
-
// If
|
|
956
|
-
// tool continuation), but the fallback model returned text instead of tool_calls —
|
|
965
|
+
// If we're in a tool loop but the fallback returned text instead of tool_calls —
|
|
957
966
|
// it ignored the JSON format. Try next model in chain.
|
|
958
|
-
|
|
959
|
-
const inToolLoop = lastMsg?.role === "tool" || lastMsg?.role === "function";
|
|
960
|
-
if (hasTools && inToolLoop && !result.tool_calls?.length && result.content) {
|
|
967
|
+
if (inToolLoop && !result.tool_calls?.length && result.content) {
|
|
961
968
|
debugLog("FALLBACK-NO-TOOLS", `${fallbackModel} returned text instead of tool_calls in tool loop`, { contentLen: result.content.length, preview: result.content.slice(0, 80) });
|
|
962
969
|
throw new Error(`${fallbackModel} returned text instead of tool_calls`);
|
|
963
970
|
}
|
package/src/tool-protocol.ts
CHANGED
|
@@ -188,6 +188,16 @@ export function parseToolCallResponse(text: string): CliToolResult {
|
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
// Last resort: try to rescue tool_calls from anywhere in the text
|
|
192
|
+
// Models sometimes output tool_calls JSON with surrounding text that breaks other strategies
|
|
193
|
+
if (trimmed.includes("tool_calls")) {
|
|
194
|
+
const rescued = tryRescueToolCallsFromContent(trimmed);
|
|
195
|
+
if (rescued) {
|
|
196
|
+
debugLog("PARSE", `rescue-from-raw → tool_calls`, { toolCalls: rescued.tool_calls?.length ?? 0 });
|
|
197
|
+
return rescued;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
191
201
|
// Fallback: treat entire text as content
|
|
192
202
|
debugLog("PARSE", "no JSON found → raw content", { len: trimmed.length, preview });
|
|
193
203
|
return { content: trimmed || null };
|
|
@@ -307,37 +317,49 @@ function tryExtractCodeBlock(text: string): string | null {
|
|
|
307
317
|
return match?.[1]?.trim() ?? null;
|
|
308
318
|
}
|
|
309
319
|
|
|
310
|
-
/** Find
|
|
320
|
+
/** Find a balanced { ... } JSON object in text. Tries multiple start positions if the first fails to parse. */
|
|
311
321
|
function tryExtractEmbeddedJson(text: string): string | null {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
depth
|
|
337
|
-
if (
|
|
338
|
-
|
|
322
|
+
let searchFrom = 0;
|
|
323
|
+
while (searchFrom < text.length) {
|
|
324
|
+
const start = text.indexOf("{", searchFrom);
|
|
325
|
+
if (start === -1) return null;
|
|
326
|
+
|
|
327
|
+
let depth = 0;
|
|
328
|
+
let inString = false;
|
|
329
|
+
let escaped = false;
|
|
330
|
+
|
|
331
|
+
for (let i = start; i < text.length; i++) {
|
|
332
|
+
const ch = text[i];
|
|
333
|
+
if (escaped) {
|
|
334
|
+
escaped = false;
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
if (ch === "\\") {
|
|
338
|
+
escaped = true;
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
if (ch === '"') {
|
|
342
|
+
inString = !inString;
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
if (inString) continue;
|
|
346
|
+
if (ch === "{") depth++;
|
|
347
|
+
if (ch === "}") {
|
|
348
|
+
depth--;
|
|
349
|
+
if (depth === 0) {
|
|
350
|
+
const candidate = text.slice(start, i + 1);
|
|
351
|
+
// Verify it actually parses as JSON before returning
|
|
352
|
+
try {
|
|
353
|
+
JSON.parse(candidate);
|
|
354
|
+
return candidate;
|
|
355
|
+
} catch {
|
|
356
|
+
// This balanced-brace block isn't valid JSON — try next { in text
|
|
357
|
+
break;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
339
360
|
}
|
|
340
361
|
}
|
|
362
|
+
searchFrom = start + 1;
|
|
341
363
|
}
|
|
342
364
|
return null;
|
|
343
365
|
}
|