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
11 changes: 11 additions & 0 deletions src/patches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import { writeWorktreeMode } from './worktreeMode';
import { writeAllowCustomAgentModels } from './allowCustomAgentModels';
import { writeVoiceMode } from './voiceMode';
import { writeChannelsMode } from './channelsMode';
import { writeKeybindingCustomization } from './keybindingCustomization';
import {
restoreNativeBinaryFromBackup,
restoreClijsFromBackup,
Expand Down Expand Up @@ -174,6 +175,13 @@ const PATCH_DEFINITIONS = [
group: PatchGroup.ALWAYS_APPLIED,
description: `Statusline updates will be properly throttled instead of queued (or debounced)`,
},
{
id: 'keybinding-customization',
name: 'Keybinding customization',
group: PatchGroup.ALWAYS_APPLIED,
description:
'Force-enable custom keybindings when CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1',
},
// Misc Configurable
{
id: 'model-customizations',
Expand Down Expand Up @@ -663,6 +671,9 @@ export const applyCustomization = async (
),
condition: config.settings.misc?.statuslineThrottleMs != null,
},
'keybinding-customization': {
fn: c => writeKeybindingCustomization(c),
},
// Misc Configurable
'patches-applied-indication': {
fn: c =>
Expand Down
34 changes: 34 additions & 0 deletions src/patches/keybindingCustomization.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { describe, expect, it } from 'vitest';

import { writeKeybindingCustomization } from './keybindingCustomization';

describe('keybindingCustomization', () => {
it('bypasses the keybinding customization gate', () => {
const file =
'const x=1;' +
'function lE(){return u$("tengu_keybinding_customization_release",!1)}' +
'function DLK(H){let $=new Date()}';

const result = writeKeybindingCustomization(file);

expect(result).not.toBeNull();
expect(result).toContain(
'function lE(){return !0;return u$("tengu_keybinding_customization_release",!1)}'
);
});

it('returns unchanged file when already patched', () => {
const file =
'const x=1;' +
'function lE(){return !0;return u$("tengu_keybinding_customization_release",!1)}' +
'function DLK(H){let $=new Date()}';

const result = writeKeybindingCustomization(file);

expect(result).toBe(file);
});

it('returns null when the gate pattern is absent', () => {
expect(writeKeybindingCustomization('const x=1;')).toBeNull();
});
});
36 changes: 36 additions & 0 deletions src/patches/keybindingCustomization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { showDiff } from './index';
import { debug } from '../utils';

export const writeKeybindingCustomization = (
oldFile: string
): string | null => {
const alreadyPatched =
/function [$\w]+\(\)\{return !0;return [$\w]+\("tengu_keybinding_customization_release"/;

if (alreadyPatched.test(oldFile)) {
debug('patch: keybindingCustomization: already patched');
return oldFile;
}

const pattern =
/function [$\w]+\(\)\{return [$\w]+\("tengu_keybinding_customization_release"/;

const match = oldFile.match(pattern);

if (!match || match.index === undefined) {
debug(
'patch: keybindingCustomization: failed to find keybinding customization gate pattern'
);
return null;
}

const insertIndex = match.index + match[0].indexOf('{') + 1;
const insertion = 'return !0;';

const newFile =
oldFile.slice(0, insertIndex) + insertion + oldFile.slice(insertIndex);

showDiff(oldFile, newFile, insertion, insertIndex, insertIndex);

return newFile;
};