@@ -109,7 +109,7 @@ async function readAutomation(
109109
110110 return {
111111 name,
112- prompt : readPrompt ( resolved . data . prompt , fileName ) ,
112+ prompt : readPrompt ( getOwnEntry ( resolved . data , " prompt" ) , fileName ) ,
113113 ...readAutomationFields ( resolved . data , fileName )
114114 } ;
115115}
@@ -130,12 +130,12 @@ function readAutomationFields(
130130 frontmatter : Record < string , unknown > ,
131131 fileName : string
132132) : Omit < AutomationDefinition , "name" | "prompt" > {
133- const label = readOptionalString ( frontmatter . label , "label" , fileName ) ;
134- const source = readOptionalString ( frontmatter . source , "source" , fileName ) ;
135- const agent = readOptionalString ( frontmatter . agent , "agent" , fileName ) ;
136- const mcp = readOptionalMcp ( frontmatter . mcp , fileName ) ;
137- const allow = readOptionalStringArray ( frontmatter . allow , "allow" , fileName ) ;
138- const prefix = readOptionalPrefix ( frontmatter . prefix , fileName ) ;
133+ const label = readOptionalString ( getOwnEntry ( frontmatter , " label" ) , "label" , fileName ) ;
134+ const source = readOptionalString ( getOwnEntry ( frontmatter , " source" ) , "source" , fileName ) ;
135+ const agent = readOptionalString ( getOwnEntry ( frontmatter , " agent" ) , "agent" , fileName ) ;
136+ const mcp = readOptionalMcp ( getOwnEntry ( frontmatter , " mcp" ) , fileName ) ;
137+ const allow = readOptionalStringArray ( getOwnEntry ( frontmatter , " allow" ) , "allow" , fileName ) ;
138+ const prefix = readOptionalPrefix ( getOwnEntry ( frontmatter , " prefix" ) , fileName ) ;
139139
140140 return {
141141 ...( label === undefined ? { } : { label } ) ,
@@ -259,32 +259,32 @@ function readOptionalMcp(
259259 ) ;
260260 }
261261
262- const command = serverValue . command ;
262+ const command = getOwnEntry ( serverValue , " command" ) ;
263263 if ( typeof command !== "string" ) {
264264 throw new Error (
265265 `Automation "${ fileName } " has invalid "mcp.${ serverName } .command" frontmatter. Expected a string.`
266266 ) ;
267267 }
268268
269- const args = serverValue . args ;
269+ const args = getOwnEntry ( serverValue , " args" ) ;
270270 if ( args !== undefined && ( ! Array . isArray ( args ) || args . some ( ( item ) => typeof item !== "string" ) ) ) {
271271 throw new Error (
272272 `Automation "${ fileName } " has invalid "mcp.${ serverName } .args" frontmatter. Expected an array of strings.`
273273 ) ;
274274 }
275275
276- const env = serverValue . env ;
276+ const env = getOwnEntry ( serverValue , " env" ) ;
277277 if ( env !== undefined && ! isStringRecord ( env ) ) {
278278 throw new Error (
279279 `Automation "${ fileName } " has invalid "mcp.${ serverName } .env" frontmatter. Expected an object of strings.`
280280 ) ;
281281 }
282282
283- mcp [ serverName ] = {
283+ defineDataProperty ( mcp , serverName , {
284284 command,
285285 ...( args === undefined ? { } : { args } ) ,
286286 ...( env === undefined ? { } : { env } )
287- } ;
287+ } ) ;
288288 }
289289
290290 return mcp ;
@@ -302,6 +302,19 @@ function isRecord(value: unknown): value is Record<string, unknown> {
302302 return typeof value === "object" && value !== null && ! Array . isArray ( value ) ;
303303}
304304
305+ function getOwnEntry ( record : Record < string , unknown > , key : string ) : unknown {
306+ return Object . prototype . hasOwnProperty . call ( record , key ) ? record [ key ] : undefined ;
307+ }
308+
309+ function defineDataProperty ( object : Record < string , unknown > , key : string , value : unknown ) : void {
310+ Object . defineProperty ( object , key , {
311+ configurable : true ,
312+ enumerable : true ,
313+ value,
314+ writable : true
315+ } ) ;
316+ }
317+
305318function isStringRecord ( value : unknown ) : value is Record < string , string > {
306319 if ( ! isRecord ( value ) ) {
307320 return false ;
0 commit comments