Skip to content
Closed
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
10 changes: 10 additions & 0 deletions fix-hooks-processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
with open('src/features/hooks/hooks-processor.ts', 'r') as f:
content = f.read()

bad_string = " supportedEvents: KILO_HOOK_EVENTS,\n OPENCODE_HOOK_EVENTS,"
good_string = " supportedEvents: OPENCODE_HOOK_EVENTS,"

content = content.replace(bad_string, good_string)

with open('src/features/hooks/hooks-processor.ts', 'w') as f:
f.write(content)
50 changes: 50 additions & 0 deletions patch-hooks-processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import re

with open('src/features/hooks/hooks-processor.ts', 'r') as f:
content = f.read()

# Fix the Kilo block we added earlier
wrong_kilo_block = """ [
"kilo",
{
class: KiloHooks,
meta: {
supportsProject: true,
supportsGlobal: true,
supportsImport: false,
},
},
],"""

right_kilo_block = """ [
"kilo",
{
class: KiloHooks,
meta: {
supportsProject: true,
supportsGlobal: true,
supportsImport: false,
},
supportedEvents: KILO_HOOK_EVENTS,
supportedHookTypes: ["command"],
supportsMatcher: true,
},
],"""

if wrong_kilo_block in content:
content = content.replace(wrong_kilo_block, right_kilo_block)

# Add "kilo" to hooksProcessorToolTargetTuple
tuple_str = 'const hooksProcessorToolTargetTuple = ['
tuple_kilo = 'const hooksProcessorToolTargetTuple = [\n "kilo",'
if '"kilo"' not in content.split(tuple_str)[1].split(']')[0]:
content = content.replace(tuple_str, tuple_kilo)

# Add import KILO_HOOK_EVENTS
import_opencode_events = "OPENCODE_HOOK_EVENTS,"
import_kilo_events = "KILO_HOOK_EVENTS,\n OPENCODE_HOOK_EVENTS,"
if "KILO_HOOK_EVENTS" not in content:
content = content.replace(import_opencode_events, import_kilo_events)

with open('src/features/hooks/hooks-processor.ts', 'w') as f:
f.write(content)
66 changes: 66 additions & 0 deletions patch-hooks-types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import re

with open('src/types/hooks.ts', 'r') as f:
content = f.read()

opencode_events = """/** Hook events supported by OpenCode. */
export const OPENCODE_HOOK_EVENTS: readonly HookEvent[] = [
"sessionStart",
"preToolUse",
"postToolUse",
"stop",
"afterFileEdit",
"afterShellExecution",
"permissionRequest",
];"""

kilo_events = """/** Hook events supported by Kilo. */
export const KILO_HOOK_EVENTS: readonly HookEvent[] = [
"sessionStart",
"preToolUse",
"postToolUse",
"stop",
"afterFileEdit",
"afterShellExecution",
"permissionRequest",
];"""

if kilo_events not in content:
content = content.replace(opencode_events, kilo_events + "\n\n" + opencode_events)

with open('src/types/hooks.ts', 'w') as f:
f.write(content)
with open('src/types/hooks.ts', 'r') as f:
content = f.read()

opencode_names = """/**
* Map canonical camelCase event names to OpenCode dot-notation.
*/
export const CANONICAL_TO_OPENCODE_EVENT_NAMES: Record<string, string> = {
sessionStart: "session.created",
preToolUse: "tool.execute.before",
postToolUse: "tool.execute.after",
stop: "session.idle",
afterFileEdit: "file.edited",
afterShellExecution: "command.executed",
permissionRequest: "permission.asked",
};"""

kilo_names = """/**
* Map canonical camelCase event names to Kilo dot-notation.
*/
export const CANONICAL_TO_KILO_EVENT_NAMES: Record<string, string> = {
sessionStart: "session.created",
preToolUse: "tool.execute.before",
postToolUse: "tool.execute.after",
stop: "session.idle",
afterFileEdit: "file.edited",
afterShellExecution: "command.executed",
permissionRequest: "permission.asked",
};"""

if kilo_names not in content:
content = content.replace(opencode_names, kilo_names + "\n\n" + opencode_names)

with open('src/types/hooks.ts', 'w') as f:
f.write(content)
29 changes: 29 additions & 0 deletions patch-rulesync-skill.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import re

with open("src/features/skills/rulesync-skill.ts", "r") as f:
content = f.read()

# Add kilo to RulesyncSkillFrontmatterSchemaInternal
schema_replacement = """ opencode: z.optional(
z.looseObject({
"allowed-tools": z.optional(z.array(z.string())),
}),
),
kilo: z.optional(
z.looseObject({
"allowed-tools": z.optional(z.array(z.string())),
}),
),"""
content = content.replace(' opencode: z.optional(\n z.looseObject({\n "allowed-tools": z.optional(z.array(z.string())),\n }),\n ),', schema_replacement)

# Add kilo to RulesyncSkillFrontmatterInput
input_replacement = """ opencode?: {
"allowed-tools"?: string[];
};
kilo?: {
"allowed-tools"?: string[];
};"""
content = content.replace(' opencode?: {\n "allowed-tools"?: string[];\n };', input_replacement)

with open("src/features/skills/rulesync-skill.ts", "w") as f:
f.write(content)
12 changes: 12 additions & 0 deletions patch-subagents-processor-tuple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import re

with open('src/features/subagents/subagents-processor.ts', 'r') as f:
content = f.read()

tuple_str = 'const subagentsProcessorToolTargetTuple = ['
tuple_kilo = 'const subagentsProcessorToolTargetTuple = [\n "kilo",'
if '"kilo"' not in content.split(tuple_str)[1].split(']')[0]:
content = content.replace(tuple_str, tuple_kilo)

with open('src/features/subagents/subagents-processor.ts', 'w') as f:
f.write(content)
32 changes: 32 additions & 0 deletions patch-subagents-processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import re

with open('src/features/subagents/subagents-processor.ts', 'r') as f:
content = f.read()

opencode_import = 'import { OpenCodeSubagent } from "./opencode-subagent.js";'
kilo_import = 'import { KiloSubagent } from "./kilo-subagent.js";'

if kilo_import not in content:
content = content.replace(opencode_import, kilo_import + "\n" + opencode_import)

opencode_block = """ [
"opencode",
{
class: OpenCodeSubagent,
meta: { supportsSimulated: false, supportsGlobal: true, filePattern: "*.md" },
},
],"""

kilo_block = """ [
"kilo",
{
class: KiloSubagent,
meta: { supportsSimulated: false, supportsGlobal: true, filePattern: "*.md" },
},
],"""

if kilo_block not in content:
content = content.replace(opencode_block, kilo_block + "\n" + opencode_block)

with open('src/features/subagents/subagents-processor.ts', 'w') as f:
f.write(content)
Loading