Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: let the Layered Intelligence loop use any provider type, not just CLI

[._.]/ Adam Eivy3db77842a3c8
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
new file mode 100644
index 0000000000..4ff74baa34
--- /dev/null
+++ b/.changelog/NEXT.md
@@ -0,0 +1,5 @@
+# Unreleased
+
+## Fixed
+
+- **Layered Intelligence loop now supports every provider type.** The per-app AI-provider picker previously listed only `cli` providers, while the reasoning call went through the api-only `callProviderAISimple` — so a selected CLI provider failed at runtime with "requires an API-based provider," and API/TUI providers (Ollama, LM Studio, Claude/Codex/OpenCode TUI, etc.) never appeared at all. The reasoning call now routes through the unified `runPromptThroughProvider`, which dispatches on `provider.type`, and the picker lists all enabled `cli`/`api`/`tui` providers. CLI/TUI spawns run in the app's repo (`cwd`).
diff --git a/client/src/components/apps/EditAppDrawer.jsx b/client/src/components/apps/EditAppDrawer.jsx
index 0a46c3c5dd..83205a608b 100644
--- a/client/src/components/apps/EditAppDrawer.jsx
+++ b/client/src/components/apps/EditAppDrawer.jsx
@@ -10,6 +10,7 @@ import Banner from '../ui/Banner';
import useDrawerTab from '../../hooks/useDrawerTab';
import { copyToClipboard } from '../../lib/clipboard';
import LayeredIntelligenceTab, { buildLayeredIntelligenceUpdate } from './LayeredIntelligenceTab';
+import { PROVIDER_TYPES } from '../../utils/providers';
const WORK_TRACKER_OPTIONS = [
{ value: 'auto', label: 'Auto (detect from git origin)' },
@@ -172,7 +173,11 @@ export default function EditAppDrawer({ app, onClose, onSave }) {
setLiConfig(cfg);
setLiBaseline(cfg);
setLiIsPortos(!!li?.isPortos);
- setLiProviders((provData?.providers || []).filter(p => p.type === 'cli' && p.enabled !== false));
+ // The loop reasons through runPromptThroughProvider, which dispatches on
+ // provider.type — so any enabled provider of a known type is selectable
+ // (Claude Code, Codex, OpenCode, Ollama/LM Studio API, TUI variants…).
+ const runnableTypes = Object.values(PROVIDER_TYPES);
+ setLiProviders((provData?.providers || []).filter(p => runnableTypes.includes(p.type) && p.enabled !== false));
setLiError(!cfg);
setLiLoaded(true);
}).catch(() => {
diff --git a/server/services/autonomousJobs/layeredIntelligenceHandler.js b/server/services/autonomousJobs/layeredIntelligenceHandler.js
index 17be0d5f19..4f6b346d37 100644
--- a/server/services/autonomousJobs/layeredIntelligenceHandler.js
+++ b/server/services/autonomousJobs/layeredIntelligenceHandler.js
@@ -146,7 +146,7 @@ export async function processApp(app, deps = {}) {
// ---- Layer 2: REASON ----
const prompt = buildPrompt({ app, config, sources, openIssues, isPortos })
- const llm = await resolveLLM(config, callLLM)
+ const llm = await resolveLLM(config, callLLM, cwd)
if (!llm.ok) {
await recordRun(app, config, now)
return { app: app.id, action: 'no-op', reason: llm.reason }
@@ -283,11 +283,20 @@ async function fileProposal({ filer, forgeCli, cwd, app, proposal, jira }) {
/**
* Resolve the LLM call function. Prefers an injected `callLLM(prompt)`; otherwise
- * resolves the active/overridden provider and returns a bound
- * callProviderAISimple. Returns `{ ok: false, reason }` when no provider is
- * available (a no-op for that app, never a throw).
+ * resolves the active/overridden provider and returns a bound call through the
+ * unified `runPromptThroughProvider`. Returns `{ ok: false, reason }` when no
+ * provider is available (a no-op for that app, never a throw).
+ *
+ * Routing through runPromptThroughProvider (rather than the api-only
+ * callProviderAISimple) lets the loop reason with EVERY provider type the user
+ * can configure — `api` (Ollama, LM Studio), `cli` (Claude Code, Codex,
+ * OpenCode, Antigravity), and `tui` — not just API providers. It dispatches on
+ * `provider.type` and returns `{ text }`, throwing on failure; we convert a
+ * throw back to the `{ error }` shape processApp already branches on. `cwd` is
+ * the app's repo path so CLI/TUI spawns land in the right directory (no-op for
+ * API providers).
*/
-async function resolveLLM(config, injected) {
+async function resolveLLM(config, injected, cwd) {
if (typeof injected === 'function') return { ok: true, call: injected }
const { getActiveProvider, getProviderById } = await import('../providers.js')
const provider = config.providerId
@@ -295,14 +304,16 @@ async function resolveLLM(config, injected) {
: await getActiveProvider().catch(() => null)
if (!provider) return { ok: false, reason: 'no-provider' }
const model = config.model || provider.defaultModel
- const { callProviderAISimple } = await import('../../lib/aiProvider.js')
+ const { runPromptThroughProvider } = await import('../../lib/promptRunner.js')
return {
ok: true,
- call: (prompt) => callProviderAISimple(provider, model, prompt, {
- op: `layered-intelligence:${provider.id}`,
- opLabel: 'Layered Intelligence reasoning…',
- max_tokens: 1500
- })
+ call: (prompt) => runPromptThroughProvider({
+ provider,
+ model,
+ prompt,
+ source: 'layered-intelligence',
+ cwd
+ }).catch(err => ({ error: err.message }))
}
}
diff --git a/server/services/autonomousJobs/layeredIntelligenceHandler.test.js b/server/services/autonomousJobs/layeredIntelligenceHandler.test.js
index e7935a4387..03eab5a718 100644
--- a/server/services/autonomousJobs/layeredIntelligenceHandler.test.js
+++ b/server/services/autonomousJobs/layeredIntelligenceHandler.test.js
@@ -59,6 +59,21 @@ vi.mock('../layeredIntelligence.js', async (importOriginal) => {
};
});
+// resolveLLM lazy-imports these only when NO callLLM is injected. Mocking them
+// lets us assert the real provider-resolution path routes through the unified
+// runPromptThroughProvider (which supports cli/api/tui) rather than the old
+// api-only callProviderAISimple.
+const runPromptMock = vi.fn().mockResolvedValue({ text: '{}' });
+vi.mock('../../lib/promptRunner.js', () => ({
+ runPromptThroughProvider: (...args) => runPromptMock(...args)
+}));
+const getProviderByIdMock = vi.fn();
+const getActiveProviderMock = vi.fn();
+vi.mock('../providers.js', () => ({
+ getProviderById: (...args) => getProviderByIdMock(...args),
+ getActiveProvider: (...args) => getActiveProviderMock(...args)
+}));
+
import { isAppDue, processApp, runLayeredIntelligence } from './layeredIntelligenceHandler.js';
import { getActiveApps } from '../apps.js';
@@ -87,6 +102,12 @@ beforeEach(() => {
forgeState.jiraBlockingApplied = [];
forgeState.semanticResult = { available: false, duplicate: false, match: null };
resolveTrackerMock.mockResolvedValue({ resolved: 'github', forge: 'gh' });
+ runPromptMock.mockResolvedValue({ text: '{}' });
+ // Default to resolving null (no provider) — mirrors the real async signature so
+ // resolveLLM's `.catch()` never trips over a non-promise in sweep tests that
+ // don't inject callLLM.
+ getProviderByIdMock.mockReset().mockResolvedValue(null);
+ getActiveProviderMock.mockReset().mockResolvedValue(null);
});
describe('isAppDue', () => {
@@ -300,6 +321,59 @@ describe('processApp', () => {
});
});
+describe('processApp — provider resolution (no injected callLLM)', () => {
+ const app = (providerId) => ({
+ id: 'app-1', name: 'App One', repoPath: '/repo',
+ layeredIntelligence: { enabled: true, intervalMs: DAY, providerId, allowedScopes: ['app-improvement'] }
+ });
+
+ it('reasons through runPromptThroughProvider for a non-API (tui) provider', async () => {
+ getProviderByIdMock.mockResolvedValue({ id: 'claude-code-tui', type: 'tui', defaultModel: null });
+ runPromptMock.mockResolvedValue({ text: JSON.stringify({ proposal: { scope: 'app-improvement', slug: 'add-x', title: 'Add X', body: 'do it' } }) });
+ const out = await processApp(app('claude-code-tui'));
+ expect(getProviderByIdMock).toHaveBeenCalledWith('claude-code-tui');
+ expect(runPromptMock).toHaveBeenCalledWith(expect.objectContaining({
+ provider: expect.objectContaining({ id: 'claude-code-tui', type: 'tui' }),
+ source: 'layered-intelligence',
+ cwd: '/repo'
+ }));
+ expect(out.action).toBe('filed');
+ });
+
+ it('works for a cli provider too (Claude Code / Codex / OpenCode)', async () => {
+ getProviderByIdMock.mockResolvedValue({ id: 'opencode-ollama', type: 'cli', defaultModel: null });
+ runPromptMock.mockResolvedValue({ text: JSON.stringify({ proposal: { scope: 'app-improvement', slug: 'add-y', title: 'Add Y', body: 'do it' } }) });
+ const out = await processApp(app('opencode-ollama'));
+ expect(runPromptMock).toHaveBeenCalledWith(expect.objectContaining({ provider: expect.objectContaining({ type: 'cli' }) }));
+ expect(out.action).toBe('filed');
+ });
+
+ it('falls back to the active provider when no providerId is set', async () => {
+ getActiveProviderMock.mockResolvedValue({ id: 'ollama', type: 'api', defaultModel: 'llama3.2' });
+ runPromptMock.mockResolvedValue({ text: JSON.stringify({ proposal: { scope: 'app-improvement', slug: 'add-z', title: 'Add Z', body: 'do it' } }) });
+ const out = await processApp(app(null));
+ expect(getProviderByIdMock).not.toHaveBeenCalled();
+ expect(getActiveProviderMock).toHaveBeenCalled();
+ expect(out.action).toBe('filed');
+ });
+
+ it('no-ops (never throws) when the runner rejects', async () => {
+ getProviderByIdMock.mockResolvedValue({ id: 'ollama', type: 'api', defaultModel: 'llama3.2' });
+ runPromptMock.mockRejectedValue(new Error('backend down'));
+ const out = await processApp(app('ollama'));
+ expect(out.action).toBe('no-op');
+ expect(out.reason).toContain('backend down');
+ });
+
+ it('no-ops when the provider cannot be resolved', async () => {
+ getProviderByIdMock.mockResolvedValue(null);
+ const out = await processApp(app('ghost-provider'));
+ expect(out.action).toBe('no-op');
+ expect(out.reason).toBe('no-provider');
+ expect(runPromptMock).not.toHaveBeenCalled();
+ });
+});
+
describe('processApp — jira tracker', () => {
const jiraApp = (extra = {}) => ({
id: 'app-j', name: 'Jira App', repoPath: '/repo',