diff --git a/src/commands/manifest.ts b/src/commands/manifest.ts index 386c05a..a7f8a9c 100644 --- a/src/commands/manifest.ts +++ b/src/commands/manifest.ts @@ -13,10 +13,10 @@ import { export async function buildManifest(): Promise> { const manifest: Record = {}; - const home = Bun.env.HOME ?? ""; + const home = Bun.env.HOME ?? Bun.env.USERPROFILE ?? ""; const dirs = [ - `${home}/.config/opencode/command`, - `${Bun.env.PWD ?? "."}/.opencode/command`, + `${home}/.config/opencode/commands`, + `${Bun.env.PWD ?? "."}/.opencode/commands`, ]; for (const dir of dirs) { diff --git a/src/core/plugin.ts b/src/core/plugin.ts index bc6be89..94c6242 100644 --- a/src/core/plugin.ts +++ b/src/core/plugin.ts @@ -14,13 +14,14 @@ import { handleSessionIdle } from "../hooks/session-idle-hook"; */ export const createPlugin: Plugin = async ctx => { - clearLog(); const configs = await buildManifest(); const pluginConfig = await loadConfig(); setConfigs(configs); setPluginConfig(pluginConfig); + clearLog(); + // Use the v1 client from OpenCode - it has internal fetch configured properly // The internal HTTP client (client.client) can be used for undocumented endpoints setClient(ctx.client); diff --git a/src/parsing/frontmatter.ts b/src/parsing/frontmatter.ts index 2189ff9..4abec57 100644 --- a/src/parsing/frontmatter.ts +++ b/src/parsing/frontmatter.ts @@ -5,7 +5,7 @@ import YAML from "yaml"; */ export function parseFrontmatter(content: string): Record { - const match = content.match(/^---\n([\s\S]*?)\n---/); + const match = content.replace(/^\uFEFF/, '').match(/^---\r?\n([\s\S]*?)\r?\n---/); if (!match) return {}; try { return YAML.parse(match[1]) ?? {}; @@ -15,6 +15,6 @@ export function parseFrontmatter(content: string): Record { } export function getTemplateBody(content: string): string { - const match = content.match(/^---\n[\s\S]*?\n---\n([\s\S]*)$/); + const match = content.replace(/^\uFEFF/, '').match(/^---\r?\n[\s\S]*?\r?\n---\r?\n([\s\S]*)$/); return match ? match[1].trim() : content.trim(); } diff --git a/src/types.ts b/src/types.ts index 7b07494..f183a8c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -28,6 +28,7 @@ export interface CommandConfig { export interface Subtask2Config { replace_generic: boolean; generic_return?: string; + logging?: boolean; } export interface SubtaskPart { diff --git a/src/utils/config.ts b/src/utils/config.ts index 6dc59a8..f6d8a07 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -56,6 +56,7 @@ function isValidConfig(obj: unknown): obj is Subtask2Config { typeof cfg.generic_return !== "string" ) return false; + if (typeof cfg.logging !== "boolean") return false; return true; } diff --git a/src/utils/logger.ts b/src/utils/logger.ts index da9d0ac..4bd8189 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -1,5 +1,6 @@ import * as fs from "fs"; import * as path from "path"; +import { getPluginConfig } from "../core/state"; const LOG_DIR = path.join(process.cwd(), ".logs"); const LOG_FILE = path.join(LOG_DIR, "subtask2.log"); @@ -13,6 +14,8 @@ function ensureInitialized(): boolean { if (initialized) return true; try { + const config = getPluginConfig(); + if (!config || config.logging === false) return false; if (!fs.existsSync(LOG_DIR)) { fs.mkdirSync(LOG_DIR, { recursive: true }); }