Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b9146cb
feat(kiloclaw): add kilo CLI run feature (spawn, poll, UI)
RSO Mar 26, 2026
6733919
Fix dev-CLI
RSO Mar 27, 2026
79f6c8b
refactor(kiloclaw): use DB run ID in CLI run URL instead of prompt qu…
RSO Mar 27, 2026
a57c708
Remove debug info
RSO Mar 27, 2026
10c7248
feat(kiloclaw): add admin CLI Runs tab with search and pagination
RSO Mar 27, 2026
f9f7a88
feat(kiloclaw): use KiloClaw default model for Kilo CLI runs
RSO Mar 27, 2026
1623df0
feat(kiloclaw): add system context prompt template for Kilo CLI runs
RSO Mar 27, 2026
89cf011
refactor(kiloclaw): use shared constants in prompt template, improve …
RSO Mar 27, 2026
7ae3a42
refactor(kiloclaw): rebrand CLI run as recovery tool
RSO Mar 27, 2026
32bf6dd
fix(kiloclaw): wrap long output lines and auto-scroll on all updates
RSO Mar 27, 2026
e11c9bc
chore: remove migration 0060 before rebase
RSO Mar 27, 2026
758740c
chore(db): regenerate migration 0060 for kiloclaw_cli_runs after rebase
RSO Mar 27, 2026
bd5ff8c
chore: fix migration numbering, type errors, and formatting after rebase
RSO Mar 27, 2026
c44f538
docs(kiloclaw): update changelog entry to match recovery branding
RSO Mar 27, 2026
ab76b66
fix(kiloclaw): set baseURL in kilo CLI config instead of deleting it
RSO Mar 27, 2026
d9cb83c
fix(kiloclaw): scope CLI run status to requested run ID and add GDPR …
RSO Mar 27, 2026
4338e58
fix(kiloclaw): revert baseURL config patch — delete stale field inste…
RSO Mar 27, 2026
8fd33f7
perf(kiloclaw): lazy-load CLI run output instead of fetching with list
RSO Mar 27, 2026
678d47b
fix(kiloclaw): scope cancelKiloCliRun DB update to specific run ID
RSO Mar 27, 2026
afee4f9
Merge branch 'main' into RSO/mousy-rest
RSO Mar 27, 2026
9fdc4c3
chore(db): remove migration 0061 before merge with main
RSO Mar 30, 2026
320c404
Merge remote-tracking branch 'origin/main' into RSO/mousy-rest
RSO Mar 30, 2026
e29785d
chore(db): regenerate migration 0064 after merge with main
RSO Mar 30, 2026
d2f111e
fix(kilo-app): fix unsafe type access in useForceUpdate hook
RSO Mar 30, 2026
991e9db
Undo unwanted change
RSO Mar 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions kiloclaw/controller/src/bootstrap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,26 @@ describe('setupDirectories', () => {
expect(env.INVOCATION_ID).toBe('1');
expect(env.GOG_KEYRING_PASSWORD).toBe('kiloclaw');
});

it('derives KILO_API_URL from KILOCODE_API_BASE_URL origin', () => {
const { deps } = fakeDeps();
const env: Record<string, string | undefined> = {
KILOCODE_API_BASE_URL: 'https://api.example.com/v1',
};

setupDirectories(env, deps);

expect(env.KILO_API_URL).toBe('https://api.example.com');
});

it('does not set KILO_API_URL when KILOCODE_API_BASE_URL is absent', () => {
const { deps } = fakeDeps();
const env: Record<string, string | undefined> = {};

setupDirectories(env, deps);

expect(env.KILO_API_URL).toBeUndefined();
});
});

// ---- applyFeatureFlags ----
Expand Down
5 changes: 5 additions & 0 deletions kiloclaw/controller/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ export function setupDirectories(env: EnvLike, deps: BootstrapDeps = defaultDeps

// GOG_KEYRING_PASSWORD is NOT a secret — see gog-credentials.ts for context.
env.GOG_KEYRING_PASSWORD = 'kiloclaw';

// Derive the API origin for the Kilo CLI from the full base URL.
if (env.KILOCODE_API_BASE_URL) {
env.KILO_API_URL = new URL(env.KILOCODE_API_BASE_URL).origin;
}
Comment on lines +193 to +195
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This replaces the providers.kilo.options.baseURL setting in the opencode.json config, which doesn't work as expected.

}

// ---- Step 3: Feature flags ----
Expand Down
2 changes: 1 addition & 1 deletion kiloclaw/controller/src/config-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export function generateBaseConfig(
return config;
}

const DEFAULT_MCPORTER_CONFIG_PATH = '/root/.openclaw/workspace/config/mcporter.json';
export const DEFAULT_MCPORTER_CONFIG_PATH = '/root/.openclaw/workspace/config/mcporter.json';

/**
* Write mcporter.json with MCP server definitions derived from environment variables.
Expand Down
2 changes: 2 additions & 0 deletions kiloclaw/controller/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { createPairingCache } from './pairing-cache';
import { registerEnvRoutes } from './routes/env';
import { registerGmailPushRoute } from './routes/gmail-push';
import { registerFileRoutes } from './routes/files';
import { registerKiloCliRunRoutes } from './routes/kilo-cli-run';
import { CONTROLLER_COMMIT, CONTROLLER_VERSION } from './version';
import { writeKiloCliConfig } from './kilo-cli-config';
import { writeGogCredentials } from './gog-credentials';
Expand Down Expand Up @@ -362,6 +363,7 @@ export async function startController(env: NodeJS.ProcessEnv = process.env): Pro
registerEnvRoutes(honoApp, supervisor, config.expectedToken);
registerGmailPushRoute(honoApp, gmailWatchSupervisor ?? null, config.expectedToken);
registerFileRoutes(honoApp, config.expectedToken, '/root/.openclaw');
registerKiloCliRunRoutes(honoApp, config.expectedToken);
honoApp.all(
'*',
createHttpProxy({
Expand Down
83 changes: 68 additions & 15 deletions kiloclaw/controller/src/kilo-cli-config.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect, vi } from 'vitest';
import { writeKiloCliConfig, type KiloCliConfigDeps } from './kilo-cli-config';
import { writeKiloCliConfig, toKiloModelId, type KiloCliConfigDeps } from './kilo-cli-config';

function fakeDeps(existingConfig?: string) {
const written: { path: string; data: string; mode: number }[] = [];
Expand Down Expand Up @@ -34,6 +34,20 @@ function baseEnv(overrides: Record<string, string> = {}): Record<string, string
};
}

describe('toKiloModelId', () => {
it('replaces kilocode/ prefix with kilo/', () => {
expect(toKiloModelId('kilocode/anthropic/claude-opus-4.6')).toBe(
'kilo/anthropic/claude-opus-4.6'
);
expect(toKiloModelId('kilocode/openai/gpt-5')).toBe('kilo/openai/gpt-5');
});

it('passes through values without kilocode/ prefix', () => {
expect(toKiloModelId('kilo/anthropic/claude-opus-4.6')).toBe('kilo/anthropic/claude-opus-4.6');
expect(toKiloModelId('other/model')).toBe('other/model');
});
});

describe('writeKiloCliConfig', () => {
it('returns false when feature flag is disabled', () => {
const { deps, written } = fakeDeps();
Expand Down Expand Up @@ -72,13 +86,25 @@ describe('writeKiloCliConfig', () => {
expect(seedConfig.$schema).toBe('https://app.kilo.ai/config.json');
// No provider block — KiloAuthPlugin auto-registers via KILO_API_KEY env var
expect(seedConfig.provider).toBeUndefined();
// No model — CLI defaults to kilo-auto/small, user picks their own
// No model when KILOCODE_DEFAULT_MODEL is not set
expect(seedConfig.model).toBeUndefined();
expect(seedConfig.permission.edit).toBe('allow');
expect(seedConfig.permission.bash).toBe('allow');
expect(written[0].mode).toBe(0o600);
});

it('includes model in seed config when KILOCODE_DEFAULT_MODEL is set', () => {
const { deps, written } = fakeDeps();
const env = baseEnv({ KILOCODE_DEFAULT_MODEL: 'kilocode/anthropic/claude-opus-4.6' });
const result = writeKiloCliConfig(env, '/tmp/kilo', deps);

expect(result).toBe(true);
expect(written.length).toBeGreaterThanOrEqual(1);
const seedConfig = JSON.parse(written[0].data);
expect(seedConfig.model).toBe('kilo/anthropic/claude-opus-4.6');
expect(seedConfig.permission.edit).toBe('allow');
});

it('does not seed config on fresh install when config already exists', () => {
const existing = JSON.stringify({ permission: { edit: 'allow', bash: 'allow' } });
const { deps, written } = fakeDeps(existing);
Expand All @@ -99,52 +125,79 @@ describe('writeKiloCliConfig', () => {
expect(written).toHaveLength(0);
});

it('patches base URL on existing config using provider.kilo', () => {
it('patches base URL on existing config using provider.kilo, stripping path to origin', () => {
const existing = JSON.stringify({ permission: { edit: 'allow', bash: 'allow' } });
const { deps, written } = fakeDeps(existing);
const env = baseEnv({
KILOCLAW_FRESH_INSTALL: 'false',
KILOCODE_API_BASE_URL: 'https://tunnel.example.com/api/gateway',
});

writeKiloCliConfig(env, '/tmp/kilo', deps);

expect(written).toHaveLength(1);
const config = JSON.parse(written[0].data);
expect(config.provider.kilo.options.baseURL).toBe('https://tunnel.example.com');
});

it('patches model from KILOCODE_DEFAULT_MODEL on existing config', () => {
const existing = JSON.stringify({ permission: { edit: 'allow', bash: 'allow' } });
const { deps, written } = fakeDeps(existing);
const env = baseEnv({
KILOCLAW_FRESH_INSTALL: 'false',
KILOCODE_API_BASE_URL: 'https://tunnel.example.com/',
KILOCODE_DEFAULT_MODEL: 'kilocode/openai/gpt-5',
});

writeKiloCliConfig(env, '/tmp/kilo', deps);

expect(written).toHaveLength(1);
const config = JSON.parse(written[0].data);
expect(config.provider.kilo.options.baseURL).toBe('https://tunnel.example.com/');
expect(config.model).toBe('kilo/openai/gpt-5');
});

it('does not set model from KILOCODE_DEFAULT_MODEL', () => {
it('patches both model and base URL when both are set', () => {
const existing = JSON.stringify({ permission: { edit: 'allow', bash: 'allow' } });
const { deps, written } = fakeDeps(existing);
const env = baseEnv({
KILOCLAW_FRESH_INSTALL: 'false',
KILOCODE_DEFAULT_MODEL: 'kilocode/openai/gpt-5',
KILOCODE_API_BASE_URL: 'https://tunnel.example.com/',
KILOCODE_API_BASE_URL: 'https://tunnel.example.com/api/gateway',
});

writeKiloCliConfig(env, '/tmp/kilo', deps);

expect(written).toHaveLength(1);
const config = JSON.parse(written[0].data);
expect(config.model).toBe('kilo/openai/gpt-5');
});

it('does not set model when KILOCODE_DEFAULT_MODEL is absent', () => {
const existing = JSON.stringify({ permission: { edit: 'allow', bash: 'allow' } });
const { deps, written } = fakeDeps(existing);
const env = baseEnv({
KILOCLAW_FRESH_INSTALL: 'false',
KILOCODE_API_BASE_URL: 'https://tunnel.example.com/api/gateway',
});

writeKiloCliConfig(env, '/tmp/kilo', deps);

expect(written).toHaveLength(1);
const config = JSON.parse(written[0].data);
// KILOCODE_DEFAULT_MODEL is for OpenClaw, not Kilo CLI
expect(config.model).toBeUndefined();
// But base URL is patched
expect(config.provider.kilo.options.baseURL).toBe('https://tunnel.example.com/');
});

it('creates provider structure when patching base URL on minimal config', () => {
const existing = JSON.stringify({});
const { deps, written } = fakeDeps(existing);
const env = baseEnv({
KILOCLAW_FRESH_INSTALL: 'false',
KILOCODE_API_BASE_URL: 'https://tunnel.example.com/',
KILOCODE_API_BASE_URL: 'https://tunnel.example.com/api/gateway',
});

writeKiloCliConfig(env, '/tmp/kilo', deps);

const config = JSON.parse(written[0].data);
expect(config.provider.kilo.options.baseURL).toBe('https://tunnel.example.com/');
expect(config.provider.kilo.options.baseURL).toBe('https://tunnel.example.com');
});

it('does not write when no env overrides set', () => {
Expand All @@ -162,7 +215,7 @@ describe('writeKiloCliConfig', () => {
const { deps, written } = fakeDeps('not valid json {{{');
const env = baseEnv({
KILOCLAW_FRESH_INSTALL: 'false',
KILOCODE_API_BASE_URL: 'https://tunnel.example.com/',
KILOCODE_API_BASE_URL: 'https://tunnel.example.com/api/gateway',
});

const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
Expand Down Expand Up @@ -197,7 +250,7 @@ describe('writeKiloCliConfig', () => {
});

const env = baseEnv({
KILOCODE_API_BASE_URL: 'https://tunnel.example.com/',
KILOCODE_API_BASE_URL: 'https://tunnel.example.com/api/gateway',
});

const result = writeKiloCliConfig(env, '/tmp/kilo', deps);
Expand All @@ -207,7 +260,7 @@ describe('writeKiloCliConfig', () => {

const finalConfig = JSON.parse(written[1].data);
expect(finalConfig.$schema).toBe('https://app.kilo.ai/config.json');
expect(finalConfig.provider.kilo.options.baseURL).toBe('https://tunnel.example.com/');
expect(finalConfig.provider.kilo.options.baseURL).toBe('https://tunnel.example.com');
expect(finalConfig.model).toBeUndefined();
});
});
43 changes: 33 additions & 10 deletions kiloclaw/controller/src/kilo-cli-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@
import fs from 'node:fs';
import path from 'node:path';

const KILO_CONFIG_DIR = '/root/.config/kilo';
const CONFIG_FILE = 'opencode.json';
export const KILO_CONFIG_DIR = '/root/.config/kilo';
export const CONFIG_FILE = 'opencode.json';

/** The Kilo CLI uses `kilo/` as the provider prefix, but KiloClaw uses `kilocode/`. */
export function toKiloModelId(kilocodeModelId: string): string {
if (kilocodeModelId.startsWith('kilocode/')) {
return 'kilo/' + kilocodeModelId.slice('kilocode/'.length);
}
return kilocodeModelId;
}

export type KiloCliConfigDeps = {
mkdirSync: (dir: string, opts: { recursive: boolean }) => void;
Expand Down Expand Up @@ -49,31 +57,46 @@ export function writeKiloCliConfig(
// No provider block needed — the KiloAuthPlugin auto-registers the "kilo"
// provider when KILO_API_KEY is in the environment (set by bootstrap).
if (isFreshInstall && !deps.existsSync(configPath)) {
const config = {
const config: Record<string, unknown> = {
$schema: 'https://app.kilo.ai/config.json',
permission: { edit: 'allow', bash: 'allow' },
};
if (env.KILOCODE_DEFAULT_MODEL) {
config.model = toKiloModelId(env.KILOCODE_DEFAULT_MODEL);
}
deps.mkdirSync(configDir, { recursive: true });
deps.writeFileSync(configPath, JSON.stringify(config, null, 2), { mode: 0o600 });
console.log('[kilo-cli] Seeded config at ' + configPath);
}

// Patch config on every boot (if it exists).
// Only writes when a change is actually made to avoid silent no-op writes.
if (deps.existsSync(configPath) && env.KILOCODE_API_BASE_URL) {
const needsBaseUrlPatch = !!env.KILOCODE_API_BASE_URL;
const needsModelPatch = !!env.KILOCODE_DEFAULT_MODEL;

if (deps.existsSync(configPath) && (needsBaseUrlPatch || needsModelPatch)) {
try {
// JSON structure is open-ended (user may add arbitrary keys), so we use `any`
// rather than a strict schema. The patch only touches provider.kilo.options.baseURL.
// rather than a strict schema.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const config: any = JSON.parse(deps.readFileSync(configPath, 'utf8'));

// Override the kilo provider's base URL for local dev (e.g., ngrok tunnel).
// In production this env var is not set and the built-in default is used.
config.provider = config.provider || {};
config.provider.kilo = config.provider.kilo || {};
config.provider.kilo.options = config.provider.kilo.options || {};
config.provider.kilo.options.baseURL = env.KILOCODE_API_BASE_URL;
console.log('[kilo-cli] Patched base URL: ' + env.KILOCODE_API_BASE_URL);
if (needsBaseUrlPatch) {
const origin = new URL(env.KILOCODE_API_BASE_URL!).origin;
config.provider = config.provider || {};
config.provider.kilo = config.provider.kilo || {};
config.provider.kilo.options = config.provider.kilo.options || {};
config.provider.kilo.options.baseURL = origin;
}

// Sync Kilo CLI's model with the user's KiloClaw default model.
// Updated on every boot so model changes in KiloClaw settings take effect.
const defaultModel = env.KILOCODE_DEFAULT_MODEL;
if (defaultModel) {
config.model = toKiloModelId(defaultModel);
}

deps.writeFileSync(configPath, JSON.stringify(config, null, 2), { mode: 0o600 });
} catch (err) {
Expand Down
Loading
Loading