1414
1515import fs from 'fs' ;
1616import path from 'path' ;
17+ import { REPO_URL } from './constants.js' ;
1718
18- const DEFAULT_AGENTS_BASE_URL =
19- 'https://github.com/PostHog/context-mill/releases/latest/download/agents' ;
19+ /** Release assets are a flat namespace: agent prompts live at the release root, like skills. */
20+ function defaultAgentsBaseUrl ( version ) {
21+ return version && version !== 'dev'
22+ ? `${ REPO_URL } /releases/download/v${ version } `
23+ : `${ REPO_URL } /releases/latest/download` ;
24+ }
2025
2126/**
2227 * The agent prompts available in source: one { flow, id } per
@@ -74,7 +79,7 @@ function assertFlowMatches(sourcePath, flow) {
7479export function buildAgents ( { configDir, distDir, baseUrl, version = 'dev' } ) {
7580 const agentsSourceDir = path . join ( configDir , 'agents' ) ;
7681 const agentsDistDir = path . join ( distDir , 'agents' ) ;
77- const resolvedBase = ( baseUrl || DEFAULT_AGENTS_BASE_URL ) . replace ( / \/ + $ / , '' ) ;
82+ const resolvedBase = ( baseUrl || defaultAgentsBaseUrl ( version ) ) . replace ( / \/ + $ / , '' ) ;
7883
7984 fs . mkdirSync ( agentsDistDir , { recursive : true } ) ;
8085
@@ -83,9 +88,9 @@ export function buildAgents({ configDir, distDir, baseUrl, version = 'dev' }) {
8388 for ( const { flow, id } of entries ) {
8489 const sourcePath = path . join ( agentsSourceDir , flow , `${ id } .md` ) ;
8590 assertFlowMatches ( sourcePath , flow ) ;
86- fs . mkdirSync ( path . join ( agentsDistDir , flow ) , { recursive : true } ) ;
87- fs . copyFileSync ( sourcePath , path . join ( agentsDistDir , flow , ` ${ id } .md` ) ) ;
88- agents . push ( { id, flow, downloadUrl : `${ resolvedBase } /${ flow } / ${ id } .md ` } ) ;
91+ const assetName = `agents- ${ flow } - ${ id } .md` ;
92+ fs . copyFileSync ( sourcePath , path . join ( agentsDistDir , assetName ) ) ;
93+ agents . push ( { id, flow, downloadUrl : `${ resolvedBase } /${ assetName } ` } ) ;
8994 }
9095
9196 const menu = { version : '1.0' , buildVersion : version , agents } ;
@@ -95,7 +100,7 @@ export function buildAgents({ configDir, distDir, baseUrl, version = 'dev' }) {
95100 ) ;
96101
97102 // Reconcile: drop dist files and folders whose source markdown was removed.
98- const keep = new Set ( entries . map ( e => path . join ( e . flow , ` ${ e . id } .md`) ) ) ;
103+ const keep = new Set ( entries . map ( e => `agents- ${ e . flow } - ${ e . id } .md`) ) ;
99104 keep . add ( 'agent-menu.json' ) ;
100105 const walk = dir => {
101106 for ( const dirent of fs . readdirSync ( dir , { withFileTypes : true } ) ) {
0 commit comments