fix(config): allow forward-compatible disabled hooks
Keep disabled_hooks aligned with runtime behavior by accepting unknown hook names instead of treating future entries as schema errors. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
import { AnyMcpNameSchema } from "../../mcp/types"
|
import { AnyMcpNameSchema } from "../../mcp/types"
|
||||||
import { BuiltinAgentNameSchema, BuiltinSkillNameSchema } from "./agent-names"
|
import { BuiltinSkillNameSchema } from "./agent-names"
|
||||||
import { AgentOverridesSchema } from "./agent-overrides"
|
import { AgentOverridesSchema } from "./agent-overrides"
|
||||||
import { BabysittingConfigSchema } from "./babysitting"
|
import { BabysittingConfigSchema } from "./babysitting"
|
||||||
import { BackgroundTaskConfigSchema } from "./background-task"
|
import { BackgroundTaskConfigSchema } from "./background-task"
|
||||||
@@ -11,7 +11,6 @@ import { CommentCheckerConfigSchema } from "./comment-checker"
|
|||||||
import { BuiltinCommandNameSchema } from "./commands"
|
import { BuiltinCommandNameSchema } from "./commands"
|
||||||
import { ExperimentalConfigSchema } from "./experimental"
|
import { ExperimentalConfigSchema } from "./experimental"
|
||||||
import { GitMasterConfigSchema } from "./git-master"
|
import { GitMasterConfigSchema } from "./git-master"
|
||||||
import { HookNameSchema } from "./hooks"
|
|
||||||
import { NotificationConfigSchema } from "./notification"
|
import { NotificationConfigSchema } from "./notification"
|
||||||
import { RalphLoopConfigSchema } from "./ralph-loop"
|
import { RalphLoopConfigSchema } from "./ralph-loop"
|
||||||
import { RuntimeFallbackConfigSchema } from "./runtime-fallback"
|
import { RuntimeFallbackConfigSchema } from "./runtime-fallback"
|
||||||
@@ -31,7 +30,7 @@ export const OhMyOpenCodeConfigSchema = z.object({
|
|||||||
disabled_mcps: z.array(AnyMcpNameSchema).optional(),
|
disabled_mcps: z.array(AnyMcpNameSchema).optional(),
|
||||||
disabled_agents: z.array(z.string()).optional(),
|
disabled_agents: z.array(z.string()).optional(),
|
||||||
disabled_skills: z.array(BuiltinSkillNameSchema).optional(),
|
disabled_skills: z.array(BuiltinSkillNameSchema).optional(),
|
||||||
disabled_hooks: z.array(HookNameSchema).optional(),
|
disabled_hooks: z.array(z.string()).optional(),
|
||||||
disabled_commands: z.array(BuiltinCommandNameSchema).optional(),
|
disabled_commands: z.array(BuiltinCommandNameSchema).optional(),
|
||||||
/** Disable specific tools by name (e.g., ["todowrite", "todoread"]) */
|
/** Disable specific tools by name (e.g., ["todowrite", "todoread"]) */
|
||||||
disabled_tools: z.array(z.string()).optional(),
|
disabled_tools: z.array(z.string()).optional(),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { describe, expect, it } from "bun:test";
|
import { describe, expect, it } from "bun:test";
|
||||||
import { mergeConfigs, parseConfigPartially } from "./plugin-config";
|
import { mergeConfigs, parseConfigPartially } from "./plugin-config";
|
||||||
import type { OhMyOpenCodeConfig } from "./config";
|
import { OhMyOpenCodeConfigSchema, type OhMyOpenCodeConfig } from "./config";
|
||||||
|
|
||||||
describe("mergeConfigs", () => {
|
describe("mergeConfigs", () => {
|
||||||
describe("categories merging", () => {
|
describe("categories merging", () => {
|
||||||
@@ -94,9 +94,9 @@ describe("mergeConfigs", () => {
|
|||||||
|
|
||||||
const result = mergeConfigs(base, override);
|
const result = mergeConfigs(base, override);
|
||||||
|
|
||||||
expect(result.agents?.oracle?.model).toBe("openai/gpt-5.4");
|
expect(result.agents?.oracle).toMatchObject({ model: "openai/gpt-5.4" });
|
||||||
expect(result.agents?.oracle?.temperature).toBe(0.5);
|
expect(result.agents?.oracle?.temperature).toBe(0.5);
|
||||||
expect(result.agents?.explore?.model).toBe("anthropic/claude-haiku-4-5");
|
expect(result.agents?.explore).toMatchObject({ model: "anthropic/claude-haiku-4-5" });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should merge disabled arrays without duplicates", () => {
|
it("should merge disabled arrays without duplicates", () => {
|
||||||
@@ -136,6 +136,23 @@ describe("mergeConfigs", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("parseConfigPartially", () => {
|
describe("parseConfigPartially", () => {
|
||||||
|
describe("disabled_hooks compatibility", () => {
|
||||||
|
//#given a config with a future hook name unknown to this version
|
||||||
|
//#when validating against the full config schema
|
||||||
|
//#then should accept the hook name so runtime and schema stay aligned
|
||||||
|
|
||||||
|
it("should accept unknown disabled_hooks values for forward compatibility", () => {
|
||||||
|
const result = OhMyOpenCodeConfigSchema.safeParse({
|
||||||
|
disabled_hooks: ["future-hook-name"],
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.success).toBe(true);
|
||||||
|
if (result.success) {
|
||||||
|
expect(result.data.disabled_hooks).toEqual(["future-hook-name"]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("fully valid config", () => {
|
describe("fully valid config", () => {
|
||||||
//#given a config where all sections are valid
|
//#given a config where all sections are valid
|
||||||
//#when parsing the config
|
//#when parsing the config
|
||||||
@@ -153,8 +170,8 @@ describe("parseConfigPartially", () => {
|
|||||||
const result = parseConfigPartially(rawConfig);
|
const result = parseConfigPartially(rawConfig);
|
||||||
|
|
||||||
expect(result).not.toBeNull();
|
expect(result).not.toBeNull();
|
||||||
expect(result!.agents?.oracle?.model).toBe("openai/gpt-5.4");
|
expect(result!.agents?.oracle).toMatchObject({ model: "openai/gpt-5.4" });
|
||||||
expect(result!.agents?.momus?.model).toBe("openai/gpt-5.4");
|
expect(result!.agents?.momus).toMatchObject({ model: "openai/gpt-5.4" });
|
||||||
expect(result!.disabled_hooks).toEqual(["comment-checker"]);
|
expect(result!.disabled_hooks).toEqual(["comment-checker"]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -196,7 +213,7 @@ describe("parseConfigPartially", () => {
|
|||||||
const result = parseConfigPartially(rawConfig);
|
const result = parseConfigPartially(rawConfig);
|
||||||
|
|
||||||
expect(result).not.toBeNull();
|
expect(result).not.toBeNull();
|
||||||
expect(result!.agents?.oracle?.model).toBe("openai/gpt-5.4");
|
expect(result!.agents?.oracle).toMatchObject({ model: "openai/gpt-5.4" });
|
||||||
expect(result!.disabled_hooks).toEqual(["not-a-real-hook"]);
|
expect(result!.disabled_hooks).toEqual(["not-a-real-hook"]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -249,7 +266,7 @@ describe("parseConfigPartially", () => {
|
|||||||
const result = parseConfigPartially(rawConfig);
|
const result = parseConfigPartially(rawConfig);
|
||||||
|
|
||||||
expect(result).not.toBeNull();
|
expect(result).not.toBeNull();
|
||||||
expect(result!.agents?.oracle?.model).toBe("openai/gpt-5.4");
|
expect(result!.agents?.oracle).toMatchObject({ model: "openai/gpt-5.4" });
|
||||||
expect((result as Record<string, unknown>)["some_future_key"]).toBeUndefined();
|
expect((result as Record<string, unknown>)["some_future_key"]).toBeUndefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user