@@ -5,7 +5,7 @@ import type { Entry } from "@opencode/schema/config"
55import { ConfigCommand } from "@opencode/schema/config/command"
66import { AppProcess } from "@opencode/util/process"
77import path from "path"
8- import { Effect , Option , Schema } from "effect"
8+ import { Effect , Result , SchemaIssue , SchemaParser } from "effect"
99import { ChildProcess } from "effect/process"
1010import { Agent } from "../../agent.js"
1111import { Config } from "../../config.js"
@@ -17,7 +17,8 @@ import { FSUtil } from "@opencode/util/fs-util"
1717import { ConfigMarkdown } from "../markdown.js"
1818import { ConfigEntryObserver } from "./entry-observer.js"
1919
20- const decodeCommand = Schema . decodeUnknownOption ( ConfigCommand . Info )
20+ const decodeCommand = SchemaParser . decodeUnknownResult ( ConfigCommand . Info )
21+ const formatIssue = SchemaIssue . makeFormatterDefault ( )
2122
2223export const Plugin = define ( {
2324 id : "opencode.config.command" ,
@@ -125,7 +126,7 @@ function loadDirectory(fs: FSUtil.Interface, directory: string) {
125126 . pipe ( Effect . orElseSucceed ( ( ) => [ ] as string [ ] ) )
126127 return yield * Effect . forEach ( files . toSorted ( ) , ( filepath ) =>
127128 fs . readFileStringSafe ( filepath ) . pipe (
128- Effect . map ( ( content ) => ( content === undefined ? undefined : decode ( directory , filepath , content ) ) ) ,
129+ Effect . flatMap ( ( content ) => ( content === undefined ? Effect . undefined : decode ( directory , filepath , content ) ) ) ,
129130 Effect . orElseSucceed ( ( ) => undefined ) ,
130131 ) ,
131132 ) . pipe (
@@ -136,20 +137,30 @@ function loadDirectory(fs: FSUtil.Interface, directory: string) {
136137 } )
137138}
138139
139- function decode ( directory : string , filepath : string , content : string ) {
140+ const decode = Effect . fnUntraced ( function * ( directory : string , filepath : string , content : string ) {
140141 const markdown = ConfigMarkdown . parseOption ( content )
141- if ( ! markdown ) return
142- const info = Option . getOrUndefined ( decodeCommand ( { ...markdown . data , template : markdown . content . trim ( ) } ) )
143- if ( ! info ) return
142+ if ( ! markdown ) {
143+ yield * Effect . logWarning ( "command file skipped" , { filepath, reason : "markdown" } )
144+ return
145+ }
146+ const info = decodeCommand ( { ...markdown . data , template : markdown . content . trim ( ) } )
147+ if ( Result . isFailure ( info ) ) {
148+ yield * Effect . logWarning ( "command file skipped" , {
149+ filepath,
150+ reason : "frontmatter" ,
151+ issue : formatIssue ( info . failure ) ,
152+ } )
153+ return
154+ }
144155 return {
145156 name : path
146157 . relative ( directory , filepath )
147158 . replaceAll ( "\\" , "/" )
148159 . replace ( / ^ ( c o m m a n d | c o m m a n d s ) \/ / , "" )
149160 . replace ( / \. m d $ / , "" ) ,
150- info,
161+ info : info . success ,
151162 }
152- }
163+ } )
153164
154165function evaluateTemplate (
155166 template : string ,
0 commit comments