* feat(hooks): add tasks-todowrite-disabler hook to block TodoRead/TodoWrite Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> * feat(task-tools): add parallel execution guidance to descriptions Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> * refactor(index): migrate task system to experimental.task_system flag Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> * docs: update AGENTS.md for experimental task system Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> * fix(task-tests): align test field names with Claude Code spec (subject, blockedBy, addBlockedBy) * fix: address Cubic review feedback Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> * fix: add optional chaining for tasksTodowriteDisabler null check --------- Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
137 lines
3.8 KiB
TypeScript
137 lines
3.8 KiB
TypeScript
import * as fs from "fs";
|
|
import * as path from "path";
|
|
import { OhMyOpenCodeConfigSchema, type OhMyOpenCodeConfig } from "./config";
|
|
import {
|
|
log,
|
|
deepMerge,
|
|
getOpenCodeConfigDir,
|
|
addConfigLoadError,
|
|
parseJsonc,
|
|
detectConfigFile,
|
|
migrateConfigFile,
|
|
} from "./shared";
|
|
|
|
export function loadConfigFromPath(
|
|
configPath: string,
|
|
ctx: unknown
|
|
): OhMyOpenCodeConfig | null {
|
|
try {
|
|
if (fs.existsSync(configPath)) {
|
|
const content = fs.readFileSync(configPath, "utf-8");
|
|
const rawConfig = parseJsonc<Record<string, unknown>>(content);
|
|
|
|
migrateConfigFile(configPath, rawConfig);
|
|
|
|
const result = OhMyOpenCodeConfigSchema.safeParse(rawConfig);
|
|
|
|
if (!result.success) {
|
|
const errorMsg = result.error.issues
|
|
.map((i) => `${i.path.join(".")}: ${i.message}`)
|
|
.join(", ");
|
|
log(`Config validation error in ${configPath}:`, result.error.issues);
|
|
addConfigLoadError({
|
|
path: configPath,
|
|
error: `Validation error: ${errorMsg}`,
|
|
});
|
|
return null;
|
|
}
|
|
|
|
log(`Config loaded from ${configPath}`, { agents: result.data.agents });
|
|
return result.data;
|
|
}
|
|
} catch (err) {
|
|
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
log(`Error loading config from ${configPath}:`, err);
|
|
addConfigLoadError({ path: configPath, error: errorMsg });
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function mergeConfigs(
|
|
base: OhMyOpenCodeConfig,
|
|
override: OhMyOpenCodeConfig
|
|
): OhMyOpenCodeConfig {
|
|
return {
|
|
...base,
|
|
...override,
|
|
agents: deepMerge(base.agents, override.agents),
|
|
categories: deepMerge(base.categories, override.categories),
|
|
disabled_agents: [
|
|
...new Set([
|
|
...(base.disabled_agents ?? []),
|
|
...(override.disabled_agents ?? []),
|
|
]),
|
|
],
|
|
disabled_mcps: [
|
|
...new Set([
|
|
...(base.disabled_mcps ?? []),
|
|
...(override.disabled_mcps ?? []),
|
|
]),
|
|
],
|
|
disabled_hooks: [
|
|
...new Set([
|
|
...(base.disabled_hooks ?? []),
|
|
...(override.disabled_hooks ?? []),
|
|
]),
|
|
],
|
|
disabled_commands: [
|
|
...new Set([
|
|
...(base.disabled_commands ?? []),
|
|
...(override.disabled_commands ?? []),
|
|
]),
|
|
],
|
|
disabled_skills: [
|
|
...new Set([
|
|
...(base.disabled_skills ?? []),
|
|
...(override.disabled_skills ?? []),
|
|
]),
|
|
],
|
|
claude_code: deepMerge(base.claude_code, override.claude_code),
|
|
};
|
|
}
|
|
|
|
export function loadPluginConfig(
|
|
directory: string,
|
|
ctx: unknown
|
|
): OhMyOpenCodeConfig {
|
|
// User-level config path - prefer .jsonc over .json
|
|
const configDir = getOpenCodeConfigDir({ binary: "opencode" });
|
|
const userBasePath = path.join(configDir, "oh-my-opencode");
|
|
const userDetected = detectConfigFile(userBasePath);
|
|
const userConfigPath =
|
|
userDetected.format !== "none"
|
|
? userDetected.path
|
|
: userBasePath + ".json";
|
|
|
|
// Project-level config path - prefer .jsonc over .json
|
|
const projectBasePath = path.join(directory, ".opencode", "oh-my-opencode");
|
|
const projectDetected = detectConfigFile(projectBasePath);
|
|
const projectConfigPath =
|
|
projectDetected.format !== "none"
|
|
? projectDetected.path
|
|
: projectBasePath + ".json";
|
|
|
|
// Load user config first (base)
|
|
let config: OhMyOpenCodeConfig =
|
|
loadConfigFromPath(userConfigPath, ctx) ?? {};
|
|
|
|
// Override with project config
|
|
const projectConfig = loadConfigFromPath(projectConfigPath, ctx);
|
|
if (projectConfig) {
|
|
config = mergeConfigs(config, projectConfig);
|
|
}
|
|
|
|
config = {
|
|
...config,
|
|
};
|
|
|
|
log("Final merged config", {
|
|
agents: config.agents,
|
|
disabled_agents: config.disabled_agents,
|
|
disabled_mcps: config.disabled_mcps,
|
|
disabled_hooks: config.disabled_hooks,
|
|
claude_code: config.claude_code,
|
|
});
|
|
return config;
|
|
}
|