@@ -28,29 +28,50 @@ const PROMPTS_BY_COMMAND: Record<string, { rubric: string; outputFormat: string
2828
2929// Commandments loading: fetch from GitHub > COMMANDMENTS_PATH env var > vendored fallback
3030const VENDORED_COMMANDMENTS = join ( __dirname , "prompts/commandments.yaml" ) ;
31- const GITHUB_COMMANDMENTS_URL =
32- "https://raw.githubusercontent.com/PostHog/context-mill/main/transformation-config/commandments.yaml" ;
31+ // Try the post-rename `context/` path first, fall back to `transformation-config/`
32+ // so this works whether or not the context-mill rename has landed on main.
33+ const GITHUB_COMMANDMENTS_URLS = [
34+ "https://raw.githubusercontent.com/PostHog/context-mill/main/context/commandments.yaml" ,
35+ "https://raw.githubusercontent.com/PostHog/context-mill/main/transformation-config/commandments.yaml" ,
36+ ] ;
3337
3438// Docs loading: fetch integration config from context-mill to get tag -> doc URL mapping
35- const GITHUB_INTEGRATION_CONFIG_URL =
36- "https://raw.githubusercontent.com/PostHog/context-mill/main/transformation-config/skills/integration/config.yaml" ;
39+ const GITHUB_INTEGRATION_CONFIG_URLS = [
40+ "https://raw.githubusercontent.com/PostHog/context-mill/main/context/skills/integration/config.yaml" ,
41+ "https://raw.githubusercontent.com/PostHog/context-mill/main/transformation-config/skills/integration/config.yaml" ,
42+ ] ;
43+
44+ /**
45+ * Fetch the first URL that returns OK. Treats network errors and non-2xx as
46+ * "try next URL". Returns null only when every URL failed.
47+ */
48+ async function fetchFirstOk ( urls : string [ ] ) : Promise < { url : string ; body : string } | null > {
49+ for ( const url of urls ) {
50+ try {
51+ const response = await fetch ( url , { signal : AbortSignal . timeout ( 5000 ) } ) ;
52+ if ( response . ok ) {
53+ return { url, body : await response . text ( ) } ;
54+ }
55+ } catch {
56+ // fall through to next URL
57+ }
58+ }
59+ return null ;
60+ }
3761
3862let _commandmentsCache : string | null = null ;
3963
4064async function fetchCommandments ( ) : Promise < string > {
4165 if ( _commandmentsCache ) return _commandmentsCache ;
4266
43- // 1. Try fetching latest from GitHub
44- try {
45- const response = await fetch ( GITHUB_COMMANDMENTS_URL , { signal : AbortSignal . timeout ( 5000 ) } ) ;
46- if ( response . ok ) {
47- _commandmentsCache = await response . text ( ) ;
48- console . log ( "Loaded commandments from GitHub (latest)" ) ;
49- return _commandmentsCache ;
50- }
51- } catch {
52- console . warn ( "Warning: Could not fetch commandments from GitHub, trying local fallbacks" ) ;
67+ // 1. Try fetching latest from GitHub (tries both context/ and transformation-config/)
68+ const fetched = await fetchFirstOk ( GITHUB_COMMANDMENTS_URLS ) ;
69+ if ( fetched ) {
70+ _commandmentsCache = fetched . body ;
71+ console . log ( `Loaded commandments from GitHub (latest): ${ fetched . url } ` ) ;
72+ return _commandmentsCache ;
5373 }
74+ console . warn ( "Warning: Could not fetch commandments from GitHub, trying local fallbacks" ) ;
5475
5576 // 2. Try COMMANDMENTS_PATH env var (local context-mill checkout)
5677 if ( process . env . COMMANDMENTS_PATH ) {
@@ -107,16 +128,13 @@ let _docsConfigCache: string | null = null;
107128async function fetchIntegrationConfig ( ) : Promise < string > {
108129 if ( _docsConfigCache ) return _docsConfigCache ;
109130
110- try {
111- const response = await fetch ( GITHUB_INTEGRATION_CONFIG_URL , { signal : AbortSignal . timeout ( 5000 ) } ) ;
112- if ( response . ok ) {
113- _docsConfigCache = await response . text ( ) ;
114- console . log ( "Loaded integration config from GitHub (latest)" ) ;
115- return _docsConfigCache ;
116- }
117- } catch {
118- console . warn ( "Warning: Could not fetch integration config from GitHub" ) ;
131+ const fetched = await fetchFirstOk ( GITHUB_INTEGRATION_CONFIG_URLS ) ;
132+ if ( fetched ) {
133+ _docsConfigCache = fetched . body ;
134+ console . log ( `Loaded integration config from GitHub (latest): ${ fetched . url } ` ) ;
135+ return _docsConfigCache ;
119136 }
137+ console . warn ( "Warning: Could not fetch integration config from GitHub" ) ;
120138
121139 return "" ;
122140}
0 commit comments