feat(backends): multi-backend intelligence layer — LLM + Agent backends, persona-loading agents, honest CLI commands

Add IntelligenceBackend abstraction with two categories:
- LLMBackend (OllamaLocal, OllamaCloud): CI runs tool loop, provides tools, constructs prompts
- AgentBackend (Opencode): agent runs own tool loop, CI serializes request

Refactor all 18 agents from hardcoded stubs to persona loaders that delegate
to the active backend or fail honestly when no backend is available.

Refactor OrchestratorAgent.executeStage() from monolithic switch to agent
delegation via STAGE_AGENT_MAP for intelligent stages (research, plan, execute,
verify), with mechanical stages (specify, clarify, complete) staying inline.

Wire CLI commands with --backend flag and auto-detection (opencode →
ollama-local → ollama-cloud). Harden rollback/ship with real git operations.
No command returns fake success.
This commit is contained in:
CI
2026-05-29 15:58:34 +00:00
parent ddf04792c7
commit 940b85bfae
33 changed files with 1828 additions and 100 deletions
+81
View File
@@ -0,0 +1,81 @@
import { OllamaBaseBackend, OllamaMessage, OllamaChatResponse } from "./ollama-base.js";
import { OllamaLocalConfig } from "./types.js";
import { ToolRegistry } from "./tool-registry.js";
export class OllamaLocalBackend extends OllamaBaseBackend {
readonly name = "ollama-local";
private localConfig: OllamaLocalConfig;
constructor(config?: OllamaLocalConfig) {
super(config);
this.localConfig = config || { base_url: "http://localhost:11434", model_profile: "balanced" };
}
async isAvailable(): Promise<boolean> {
try {
const response = await fetch(`${this.localConfig.base_url}/api/tags`, {
signal: AbortSignal.timeout(5000),
});
return response.ok;
} catch {
return false;
}
}
protected resolveModel(): string {
if (this.localConfig.model) return this.localConfig.model;
const models = this.fetchAvailableModelsSync();
return this.modelProfileToModel(this.localConfig.model_profile, models);
}
protected async callModel(
messages: OllamaMessage[],
model: string,
toolRegistry: ToolRegistry
): Promise<OllamaChatResponse> {
const url = `${this.localConfig.base_url}/v1/chat/completions`;
const body: Record<string, unknown> = {
model,
messages: messages.map((m) => {
const msg: Record<string, unknown> = { role: m.role, content: m.content };
if (m.name) msg.name = m.name;
if (m.tool_calls) msg.tool_calls = m.tool_calls;
return msg;
}),
tools: toolRegistry.getOpenAIToolSchema(),
stream: false,
};
const timeout = this.localConfig.timeout_ms || 10000;
const response = await fetch(url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
signal: AbortSignal.timeout(timeout),
});
if (!response.ok) {
const errorText = await response.text().catch(() => "unknown error");
throw new Error(`Ollama local API error (${response.status}): ${errorText}`);
}
return (await response.json()) as OllamaChatResponse;
}
private fetchAvailableModelsSync(): string[] {
try {
const { execSync } = require("node:child_process");
const result = execSync(`curl -s ${this.localConfig.base_url}/api/tags`, {
encoding: "utf-8",
timeout: 5000,
});
const data = JSON.parse(result) as { models?: Array<{ name: string }> };
return (data.models || []).map((m) => m.name);
} catch {
return [];
}
}
}