Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(cline): keep CLINE_PROVIDER from the child, track set_model in the model option, honour --config for sign-in, 0m reset

Krishna Dobhaled8e9593f733
diff --git a/server/drivers/acp/cline.test.ts b/server/drivers/acp/cline.test.ts
index 3757641ba9..7a8f9d2d36 100644
--- a/server/drivers/acp/cline.test.ts
+++ b/server/drivers/acp/cline.test.ts
@@ -160,17 +160,46 @@ describe("Cline ACP driver", () => {
]);
calls.length = 0;
const switched = [{ id: "provider", currentValue: "cline-pass" }, { id: "model", currentValue: "cline-pass/glm-5.3" }];
- await CLINE_SUPPORT.configureSession!({ ...base, configOptions: switched, env: { CLINE_PROVIDER: "openai-compatible", CLINE_MODEL: "fixture-model" }, turn: { model: "cline-default" } });
+ await CLINE_SUPPORT.configureSession!({ ...base, configOptions: switched, env: { OMB_CLINE_PROVIDER: "openai-compatible", CLINE_MODEL: "fixture-model" }, turn: { model: "cline-default" } });
expect(calls).toEqual([
["session/set_config_option", { sessionId: "s", configId: "provider", value: "openai-compatible" }],
["session/set_model", { sessionId: "s", modelId: "fixture-model" }],
]);
});
+ it("keeps CLINE_PROVIDER from Cline but still restores it, and returns to a tier model after Cline default", async () => {
+ const env: Record<string, string | undefined> = { CLINE_PROVIDER: "openai-compatible", CLINE_MODEL: "fixture-model", CLINE_PROVIDER_SETTINGS_PATH: join(scratch, "missing.json") };
+ CLINE_SUPPORT.transformEnv!(env, { cli: "cline" } as any, "cline", undefined as any);
+ expect(env.CLINE_PROVIDER).toBeUndefined();
+ const oauth: Record<string, string | undefined> = { CLINE_PROVIDER: "cline", CLINE_PROVIDER_SETTINGS_PATH: join(scratch, "missing.json") };
+ CLINE_SUPPORT.transformEnv!(oauth, { cli: "cline" } as any, "cline", undefined as any);
+ expect(CLINE_SUPPORT.pickAuthMethod([{ id: "cline" }], oauth)).toBe("cline");
+ const calls: Array<[string, unknown]> = [];
+ let options = [{ id: "provider", currentValue: "cline-pass" }, { id: "model", currentValue: "cline-pass/glm-5.3" }];
+ const request = async (method: string, params: any) => {
+ calls.push([method, params.value ?? params.modelId]);
+ if (method !== "session/set_config_option") return {};
+ options = options.map((entry) => entry.id === params.configId ? { ...entry, currentValue: params.value } : entry);
+ return { configOptions: options };
+ };
+ const run = (model: string) => CLINE_SUPPORT.configureSession!({
+ request, sessionId: "s", env, config: { cli: "cline" }, sessionModels: [], currentModelId: undefined, configOptions: options, notice() {}, turn: { model },
+ } as any);
+ await run("cline-default");
+ await run("cline-pass/glm-5.3");
+ expect(calls).toEqual([
+ ["session/set_config_option", "openai-compatible"],
+ ["session/set_model", "fixture-model"],
+ ["session/set_config_option", "cline-pass"],
+ ["session/set_config_option", "cline-pass/glm-5.3"],
+ ]);
+ });
+
it("reads a ClinePass limit as a usage limit with its reset", () => {
const now = Date.UTC(2026, 10, 18);
const limit = clinePlanLimit(new Error("Internal error: You have reached your weekly Clinepass limit. The limit resets in 8h 30m, please try again later. (session/prompt)"), now);
expect(limit).toMatchObject({ acpUsageLimit: true, facts: { limitResetsAt: now + (8 * 60 + 31) * 60_000 } });
+ expect(clinePlanLimit(new Error("You have reached your weekly Clinepass limit. The limit resets in 0m."), now)?.facts.limitResetsAt).toBe(now + 60_000);
expect(clinePlanLimit(new Error("You have reached your daily Clinepass limit."), now)?.facts.limitResetsAt).toBeUndefined();
expect(clinePlanLimit(new Error("You hit your rate limit"), now)).toBeUndefined();
expect(clinePlanLimit(new Error("reached your context window limit"), now)).toBeUndefined();
diff --git a/server/drivers/acp/cline.ts b/server/drivers/acp/cline.ts
index eeaff4cddf..8fd955493e 100644
--- a/server/drivers/acp/cline.ts
+++ b/server/drivers/acp/cline.ts
@@ -14,7 +14,10 @@ import { clineTierModels, clineTierProvider } from "./cline-models.ts";
const DEFAULT_OPTION = { id: "cline-default", label: "Cline default (configured)" };
const MODELS: ModelCatalog = { default: DEFAULT_OPTION.id, options: [DEFAULT_OPTION] };
-type ClineSettings = { provider: string; model?: string; apiKey?: string; auth?: { accessToken?: string; apiKey?: string } };
+// Cline 3.0.74 refuses session/set_config_option `provider` while CLINE_PROVIDER is set, so the child gets this instead.
+const PROVIDER_ENV = "OMB_CLINE_PROVIDER";
+
+type ClineSettings ={ provider: string; model?: string; apiKey?: string; auth?: { accessToken?: string; apiKey?: string } };
function savedProvider(env: Record<string, string | undefined>, cli: string): { settings: ClineSettings; fingerprint: string } | null {
try {
@@ -30,7 +33,7 @@ function savedProvider(env: Record<string, string | undefined>, cli: string): {
const text = readFileSync(path, "utf8");
const stored = JSON.parse(text);
if (stored?.version !== 1 || !stored.providers || Array.isArray(stored.providers)) return null;
- const provider = env.CLINE_PROVIDER || stored.lastUsedProvider;
+ const provider = env.CLINE_PROVIDER || env[PROVIDER_ENV] || stored.lastUsedProvider;
if (typeof provider !== "string" || !/^[\w.-]{1,100}$/.test(provider)) return null;
const settings = stored.providers[provider]?.settings;
if (!settings || settings.provider !== provider) return null;
@@ -72,7 +75,7 @@ export function clinePlanLimit(error: unknown, now = Date.now()): AcpReportedFai
}
// holds the whole engine, free models too; hold only the ClinePass models via limitFacts if that bites.
// Cline rounds the wait down to the minute.
- const resetsAt = delayMs > 0 ? now + delayMs + 60_000 : undefined;
+ const resetsAt = RESET_IN.test(text) ? now + delayMs + 60_000 : undefined;
const failure = engineFailure("Cline", "", { kind: "usage_limit", status: null, resetsAt })!;
return new AcpReportedFailure({ ...failure, ...(resetsAt === undefined ? {} : { limitResetsAt: resetsAt }) }, true);
}
@@ -112,14 +115,16 @@ export const CLINE_SUPPORT: AcpSupport = {
credentialEnv: ["CLINE_API_KEY"],
transformEnv(env, config) {
const saved = savedProvider(env, config.cli)?.settings;
- // Not CLINE_PROVIDER: Cline 3.0.74 refuses session/set_config_option `provider` while it is set.
+ const provider = env.CLINE_PROVIDER || saved?.provider;
+ delete env.CLINE_PROVIDER;
+ if (provider) env[PROVIDER_ENV] = provider;
if (!saved) return;
// ACP restores OAuth accounts itself but needs CLINE_API_KEY for BYOK; never another account's key.
if (!OAUTH.has(saved.provider)) env.CLINE_API_KEY ||= saved.apiKey || saved.auth?.apiKey;
},
spawnFingerprint: (env, config) => savedProvider(env, config.cli)?.fingerprint ?? "unconfigured",
pickAuthMethod: (methods, env) => {
- const provider = env.CLINE_PROVIDER || savedProvider(env, "cline")?.settings.provider || "";
+ const provider = env[PROVIDER_ENV] ?? "";
return !env.CLINE_API_KEY && OAUTH.has(provider) && methods.some((method) => method.id === provider) ? provider : null;
},
authFailure: "fail-request",
@@ -138,28 +143,33 @@ export const CLINE_SUPPORT: AcpSupport = {
return env.CLINE_MODEL?.trim();
},
async configureSession({ request, sessionId, env, config, turn, currentModelId, configOptions }) {
- const options = configOptions as ConfigOption[];
+ // The same array the driver keeps for the next turn, so set_model below must update its `model` entry too.
+ let options = configOptions as ConfigOption[];
const option = (id: string) => options.find((entry) => entry.id === id);
const setOption = async (configId: string, value: string) => {
const current = option(configId);
- if (current && current.currentValue !== value) await request("session/set_config_option", { sessionId, configId, value });
+ if (!current || current.currentValue === value) return;
+ const result = await request("session/set_config_option", { sessionId, configId, value }) as { configOptions?: unknown } | undefined;
+ options = Array.isArray(result?.configOptions) ? result.configOptions : options;
+ };
+ const setModel = async (modelId: string) => {
+ await request("session/set_model", { sessionId, modelId });
+ const current = option("model");
+ if (current) current.currentValue = modelId;
};
const tier = clineTierProvider(turn.model);
if (tier) {
// The agent lists only its provider's models, but runs a model it did not list.
await setOption("provider", tier);
if (option("model")) await setOption("model", turn.model!);
- else if (turn.model !== currentModelId) await request("session/set_model", { sessionId, modelId: turn.model });
+ else if (turn.model !== currentModelId) await setModel(turn.model!);
return;
}
- const saved = savedProvider(env, config.cli)?.settings;
- const provider = env.CLINE_PROVIDER || saved?.provider;
+ const provider = env[PROVIDER_ENV];
if (provider) await setOption("provider", provider);
// session/new falls back when a saved custom model is missing from Cline's built-in catalog.
- const model = env.CLINE_MODEL?.trim() || saved?.model?.trim();
- if (model && model !== (option("model")?.currentValue ?? currentModelId)) {
- await request("session/set_model", { sessionId, modelId: model });
- }
+ const model = env.CLINE_MODEL?.trim() || savedProvider(env, config.cli)?.settings.model?.trim();
+ if (model && model !== (option("model")?.currentValue ?? currentModelId)) await setModel(model);
},
reportedFailure: clineReportedFailure,
};
diff --git a/server/drivers/acp/core.ts b/server/drivers/acp/core.ts
index dd5e83fe9c..e893decc1c 100644
--- a/server/drivers/acp/core.ts
+++ b/server/drivers/acp/core.ts
@@ -1316,16 +1316,10 @@ export function createAcpDriver(support: AcpSupport): ProviderDriver<AcpConfig>
await support.configureSession({
request: async (method, params, timeoutMs) => {
const result = await request(method, params, timeoutMs ?? SESSION_CONFIG_TIMEOUT);
- if (method === "session/set_model" && params && typeof params === "object" &&
- "modelId" in params && typeof params.modelId === "string") {
- session.sessionConfigResult = {
- ...session.sessionConfigResult,
- models: { ...session.sessionConfigResult?.models, currentModelId: params.modelId },
- };
- }
- if (method === "session/set_config_option" && Array.isArray(result?.configOptions)) {
- session.sessionConfigResult = { ...session.sessionConfigResult, configOptions: result.configOptions };
+ if (method === "session/set_model" && params && typeof params === "object" && "modelId" in params && typeof params.modelId === "string") {
+ session.sessionConfigResult = { ...session.sessionConfigResult, models: { ...session.sessionConfigResult?.models, currentModelId: params.modelId } };
}
+ if (method === "session/set_config_option" && Array.isArray(result?.configOptions)) session.sessionConfigResult = { ...session.sessionConfigResult, configOptions: result.configOptions };
return result;
},
sessionId,