Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 32 additions & 0 deletions kiloclaw/controller/src/config-writer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,38 @@ describe('generateBaseConfig', () => {
expect(config.tools.profile).toBe('full');
});

it('sets session.dmScope to main on fresh install', () => {
const { deps } = fakeDeps();
const env = { ...minimalEnv(), KILOCLAW_FRESH_INSTALL: 'true' };
const config = generateBaseConfig(env, '/tmp/openclaw.json', deps);

expect(config.session.dmScope).toBe('main');
});

it('does not set session.dmScope on non-fresh boot', () => {
const { deps } = fakeDeps();
const config = generateBaseConfig(minimalEnv(), '/tmp/openclaw.json', deps);

expect(config.session?.dmScope).toBeUndefined();
});

it('preserves user session.dmScope on non-fresh boot', () => {
const existing = JSON.stringify({ session: { dmScope: 'custom' } });
const { deps } = fakeDeps(existing);
const config = generateBaseConfig(minimalEnv(), '/tmp/openclaw.json', deps);

expect(config.session.dmScope).toBe('custom');
});

it('overrides session.dmScope to main on fresh install even if previously set', () => {
const existing = JSON.stringify({ session: { dmScope: 'custom' } });
const { deps } = fakeDeps(existing);
const env = { ...minimalEnv(), KILOCLAW_FRESH_INSTALL: 'true' };
const config = generateBaseConfig(env, '/tmp/openclaw.json', deps);

expect(config.session.dmScope).toBe('main');
});

it('preserves existing config keys not touched by the patch', () => {
const existing = JSON.stringify({ custom: { key: 'value' }, gateway: { extra: true } });
const { deps } = fakeDeps(existing);
Expand Down
7 changes: 7 additions & 0 deletions kiloclaw/controller/src/config-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ export function generateBaseConfig(
config.tools.profile = 'full';
}

// Session DM scope: on fresh install, default to 'main' so DMs are routed
// to the main session. On subsequent boots, leave the user's choice untouched.
if (env.KILOCLAW_FRESH_INSTALL === 'true') {
config.session = config.session ?? {};
config.session.dmScope = 'main';
}

// Exec: KiloClaw machines have no Docker sandbox, so exec must target the
// gateway host directly. Security and ask are user-configurable via the
// provisioning preset, persisted in DO state and transported as env vars.
Expand Down
Loading