11import { execSync } from "child_process" ;
22import { mkdir , writeFile } from "fs/promises" ;
3- import { join , dirname } from "path" ;
3+ import { join , dirname , relative } from "path" ;
44import { stringify } from "yaml" ;
55import { VAPI_ENV , VAPI_BASE_URL , VAPI_TOKEN , RESOURCES_DIR , BASE_DIR } from "./config.ts" ;
66import { loadState , saveState } from "./state.ts" ;
@@ -304,6 +304,23 @@ function extractSystemPrompt(data: Record<string, unknown>): { systemPrompt: str
304304 return { systemPrompt : systemMessage . content , cleanedData } ;
305305}
306306
307+ // Deterministic key ordering: 'name' first, then alphabetical
308+ // Applied to all levels (top-level and nested objects) for stable diffs
309+ const sortMapEntries = ( a : { key : unknown } , b : { key : unknown } ) : number => {
310+ const aKey = String ( a . key ) ;
311+ const bKey = String ( b . key ) ;
312+ if ( aKey === "name" ) return - 1 ;
313+ if ( bKey === "name" ) return 1 ;
314+ return aKey . localeCompare ( bKey ) ;
315+ } ;
316+
317+ const YAML_OPTIONS = {
318+ lineWidth : 0 ,
319+ defaultStringType : "PLAIN" as const ,
320+ defaultKeyType : "PLAIN" as const ,
321+ sortMapEntries,
322+ } ;
323+
307324async function writeResourceFile (
308325 resourceType : ResourceType ,
309326 resourceId : string ,
@@ -321,11 +338,7 @@ async function writeResourceFile(
321338 const filePath = join ( dir , `${ resourceId } .md` ) ;
322339 await mkdir ( dirname ( filePath ) , { recursive : true } ) ;
323340
324- const yamlContent = stringify ( cleanedData , {
325- lineWidth : 0 ,
326- defaultStringType : "PLAIN" ,
327- defaultKeyType : "PLAIN" ,
328- } ) ;
341+ const yamlContent = stringify ( cleanedData , YAML_OPTIONS ) ;
329342
330343 const mdContent = `---\n${ yamlContent } ---\n\n${ systemPrompt } \n` ;
331344 await writeFile ( filePath , mdContent ) ;
@@ -338,11 +351,7 @@ async function writeResourceFile(
338351 const filePath = join ( dir , `${ resourceId } .yml` ) ;
339352 await mkdir ( dirname ( filePath ) , { recursive : true } ) ;
340353
341- const yamlContent = stringify ( data , {
342- lineWidth : 0 ,
343- defaultStringType : "PLAIN" ,
344- defaultKeyType : "PLAIN" ,
345- } ) ;
354+ const yamlContent = stringify ( data , YAML_OPTIONS ) ;
346355
347356 await writeFile ( filePath , yamlContent ) ;
348357
@@ -409,7 +418,8 @@ export async function pullResourceType(
409418 // Write to file
410419 const filePath = await writeResourceFile ( resourceType , resourceId , resolved ) ;
411420 const icon = isPlatformDefault ? "🔒" : isNew ? "✨" : "📝" ;
412- console . log ( ` ${ icon } ${ resourceId } -> ${ filePath } ${ isPlatformDefault ? " (platform default, read-only)" : "" } ` ) ;
421+ const relPath = relative ( BASE_DIR , filePath ) ;
422+ console . log ( ` ${ icon } ${ resourceId } -> ${ relPath } ${ isPlatformDefault ? " (platform default, read-only)" : "" } ` ) ;
413423
414424 // Update state
415425 newStateSection [ resourceId ] = resource . id ;
0 commit comments