mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-18 07:12:47 +03:00
fix(core): log command files that fail to load (#62251)
This commit is contained in:
@@ -5,7 +5,7 @@ import type { Entry } from "@opencode/schema/config"
|
||||
import { ConfigCommand } from "@opencode/schema/config/command"
|
||||
import { AppProcess } from "@opencode/util/process"
|
||||
import path from "path"
|
||||
import { Effect, Option, Schema } from "effect"
|
||||
import { Effect, Result, SchemaIssue, SchemaParser } from "effect"
|
||||
import { ChildProcess } from "effect/process"
|
||||
import { Agent } from "../../agent.js"
|
||||
import { Config } from "../../config.js"
|
||||
@@ -17,7 +17,8 @@ import { FSUtil } from "@opencode/util/fs-util"
|
||||
import { ConfigMarkdown } from "../markdown.js"
|
||||
import { ConfigEntryObserver } from "./entry-observer.js"
|
||||
|
||||
const decodeCommand = Schema.decodeUnknownOption(ConfigCommand.Info)
|
||||
const decodeCommand = SchemaParser.decodeUnknownResult(ConfigCommand.Info)
|
||||
const formatIssue = SchemaIssue.makeFormatterDefault()
|
||||
|
||||
export const Plugin = define({
|
||||
id: "opencode.config.command",
|
||||
@@ -125,7 +126,7 @@ function loadDirectory(fs: FSUtil.Interface, directory: string) {
|
||||
.pipe(Effect.orElseSucceed(() => [] as string[]))
|
||||
return yield* Effect.forEach(files.toSorted(), (filepath) =>
|
||||
fs.readFileStringSafe(filepath).pipe(
|
||||
Effect.map((content) => (content === undefined ? undefined : decode(directory, filepath, content))),
|
||||
Effect.flatMap((content) => (content === undefined ? Effect.undefined : decode(directory, filepath, content))),
|
||||
Effect.orElseSucceed(() => undefined),
|
||||
),
|
||||
).pipe(
|
||||
@@ -136,20 +137,30 @@ function loadDirectory(fs: FSUtil.Interface, directory: string) {
|
||||
})
|
||||
}
|
||||
|
||||
function decode(directory: string, filepath: string, content: string) {
|
||||
const decode = Effect.fnUntraced(function* (directory: string, filepath: string, content: string) {
|
||||
const markdown = ConfigMarkdown.parseOption(content)
|
||||
if (!markdown) return
|
||||
const info = Option.getOrUndefined(decodeCommand({ ...markdown.data, template: markdown.content.trim() }))
|
||||
if (!info) return
|
||||
if (!markdown) {
|
||||
yield* Effect.logWarning("command file skipped", { filepath, reason: "markdown" })
|
||||
return
|
||||
}
|
||||
const info = decodeCommand({ ...markdown.data, template: markdown.content.trim() })
|
||||
if (Result.isFailure(info)) {
|
||||
yield* Effect.logWarning("command file skipped", {
|
||||
filepath,
|
||||
reason: "frontmatter",
|
||||
issue: formatIssue(info.failure),
|
||||
})
|
||||
return
|
||||
}
|
||||
return {
|
||||
name: path
|
||||
.relative(directory, filepath)
|
||||
.replaceAll("\\", "/")
|
||||
.replace(/^(command|commands)\//, "")
|
||||
.replace(/\.md$/, ""),
|
||||
info,
|
||||
info: info.success,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
function evaluateTemplate(
|
||||
template: string,
|
||||
|
||||
Reference in New Issue
Block a user