@@ -4,7 +4,7 @@ import { applyEdits, modify } from "jsonc-parser";
44import { join } from "@tauri-apps/api/path" ;
55import { currentLocale , t } from "../../i18n" ;
66
7- import type { Client , PluginScope , ReloadReason , ReloadTrigger , SkillCard } from "../types" ;
7+ import type { Client , HubSkillCard , PluginScope , ReloadReason , ReloadTrigger , SkillCard } from "../types" ;
88import { addOpencodeCacheHint , isTauriRuntime } from "../utils" ;
99import skillCreatorTemplate from "../data/skill-creator.md?raw" ;
1010import {
@@ -55,6 +55,9 @@ export function createExtensionsStore(options: {
5555 const [ skills , setSkills ] = createSignal < SkillCard [ ] > ( [ ] ) ;
5656 const [ skillsStatus , setSkillsStatus ] = createSignal < string | null > ( null ) ;
5757
58+ const [ hubSkills , setHubSkills ] = createSignal < HubSkillCard [ ] > ( [ ] ) ;
59+ const [ hubSkillsStatus , setHubSkillsStatus ] = createSignal < string | null > ( null ) ;
60+
5861 const formatSkillPath = ( location : string ) => location . replace ( / [ / \\ ] S K I L L \. m d $ / i, "" ) ;
5962
6063 const [ pluginScope , setPluginScope ] = createSignal < PluginScope > ( "project" ) ;
@@ -71,10 +74,132 @@ export function createExtensionsStore(options: {
7174 // Track in-flight requests to prevent duplicate calls
7275 let refreshSkillsInFlight = false ;
7376 let refreshPluginsInFlight = false ;
77+ let refreshHubSkillsInFlight = false ;
7478 let refreshSkillsAborted = false ;
7579 let refreshPluginsAborted = false ;
80+ let refreshHubSkillsAborted = false ;
7681 let skillsLoaded = false ;
82+ let hubSkillsLoaded = false ;
7783 let skillsRoot = "" ;
84+ let hubSkillsRoot = "" ;
85+
86+ async function refreshHubSkills ( optionsOverride ?: { force ?: boolean } ) {
87+ const root = options . activeWorkspaceRoot ( ) . trim ( ) ;
88+ const openworkClient = options . openworkServerClient ( ) ;
89+ const openworkCapabilities = options . openworkServerCapabilities ( ) ;
90+ const canUseOpenworkServer =
91+ options . openworkServerStatus ( ) === "connected" &&
92+ openworkClient &&
93+ openworkCapabilities ?. hub ?. skills ?. read &&
94+ typeof ( openworkClient as any ) . listHubSkills === "function" ;
95+
96+ if ( root !== hubSkillsRoot ) {
97+ hubSkillsLoaded = false ;
98+ }
99+
100+ if ( ! optionsOverride ?. force && hubSkillsLoaded ) return ;
101+ if ( refreshHubSkillsInFlight ) return ;
102+
103+ refreshHubSkillsInFlight = true ;
104+ refreshHubSkillsAborted = false ;
105+
106+ try {
107+ setHubSkillsStatus ( null ) ;
108+
109+ if ( canUseOpenworkServer ) {
110+ const response = await ( openworkClient as any ) . listHubSkills ( ) ;
111+ if ( refreshHubSkillsAborted ) return ;
112+ const next : HubSkillCard [ ] = Array . isArray ( response ?. items )
113+ ? response . items . map ( ( entry : any ) => ( {
114+ name : String ( entry . name ?? "" ) ,
115+ description : typeof entry . description === "string" ? entry . description : undefined ,
116+ trigger : typeof entry . trigger === "string" ? entry . trigger : undefined ,
117+ source : entry . source ,
118+ } ) )
119+ : [ ] ;
120+ setHubSkills ( next ) ;
121+ if ( ! next . length ) setHubSkillsStatus ( "No hub skills found." ) ;
122+ hubSkillsLoaded = true ;
123+ hubSkillsRoot = root ;
124+ return ;
125+ }
126+
127+ // Browser fallback: fetch directly from GitHub (public catalog).
128+ const listingRes = await fetch ( "https://api.github.com/repos/different-ai/openwork-hub/contents/skills?ref=main" , {
129+ headers : { Accept : "application/vnd.github+json" } ,
130+ } ) ;
131+ if ( ! listingRes . ok ) {
132+ throw new Error ( `Failed to fetch hub catalog (${ listingRes . status } )` ) ;
133+ }
134+ const listing = ( await listingRes . json ( ) ) as any ;
135+ const dirs : string [ ] = Array . isArray ( listing )
136+ ? listing
137+ . filter ( ( entry ) => entry && entry . type === "dir" && typeof entry . name === "string" )
138+ . map ( ( entry ) => String ( entry . name ) )
139+ : [ ] ;
140+
141+ const next : HubSkillCard [ ] = dirs . map ( ( dirName ) => ( {
142+ name : dirName ,
143+ source : { owner : "different-ai" , repo : "openwork-hub" , ref : "main" , path : `skills/${ dirName } ` } ,
144+ } ) ) ;
145+
146+ if ( refreshHubSkillsAborted ) return ;
147+ const sorted = next . slice ( ) . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
148+ setHubSkills ( sorted ) ;
149+ if ( ! sorted . length ) setHubSkillsStatus ( "No hub skills found." ) ;
150+ hubSkillsLoaded = true ;
151+ hubSkillsRoot = root ;
152+ } catch ( e ) {
153+ if ( refreshHubSkillsAborted ) return ;
154+ setHubSkills ( [ ] ) ;
155+ setHubSkillsStatus ( e instanceof Error ? e . message : "Failed to load hub skills." ) ;
156+ } finally {
157+ refreshHubSkillsInFlight = false ;
158+ }
159+ }
160+
161+ async function installHubSkill ( name : string ) : Promise < { ok : boolean ; message : string } > {
162+ const trimmed = name . trim ( ) ;
163+ if ( ! trimmed ) return { ok : false , message : "Skill name is required." } ;
164+
165+ const isRemoteWorkspace = options . workspaceType ( ) === "remote" ;
166+ const openworkClient = options . openworkServerClient ( ) ;
167+ const openworkWorkspaceId = options . openworkServerWorkspaceId ( ) ;
168+ const openworkCapabilities = options . openworkServerCapabilities ( ) ;
169+ const canUseOpenworkServer =
170+ options . openworkServerStatus ( ) === "connected" &&
171+ openworkClient &&
172+ openworkWorkspaceId &&
173+ openworkCapabilities ?. hub ?. skills ?. install &&
174+ typeof ( openworkClient as any ) . installHubSkill === "function" ;
175+
176+ if ( ! canUseOpenworkServer ) {
177+ if ( isRemoteWorkspace ) {
178+ return { ok : false , message : "OpenWork server unavailable. Connect to install skills." } ;
179+ }
180+ return { ok : false , message : "Hub install requires OpenWork server." } ;
181+ }
182+
183+ options . setBusy ( true ) ;
184+ options . setError ( null ) ;
185+ setSkillsStatus ( null ) ;
186+
187+ try {
188+ const result = await ( openworkClient as any ) . installHubSkill ( openworkWorkspaceId , trimmed ) ;
189+ await refreshSkills ( { force : true } ) ;
190+ await refreshHubSkills ( { force : true } ) ;
191+ if ( ! result ?. ok ) {
192+ return { ok : false , message : "Install failed." } ;
193+ }
194+ return { ok : true , message : `Installed ${ trimmed } .` } ;
195+ } catch ( e ) {
196+ const message = e instanceof Error ? e . message : translate ( "skills.unknown_error" ) ;
197+ options . setError ( addOpencodeCacheHint ( message ) ) ;
198+ return { ok : false , message } ;
199+ } finally {
200+ options . setBusy ( false ) ;
201+ }
202+ }
78203
79204 const isPluginInstalledByName = ( pluginName : string , aliases : string [ ] = [ ] ) =>
80205 isPluginInstalled ( pluginList ( ) , pluginName , aliases ) ;
@@ -895,11 +1020,14 @@ export function createExtensionsStore(options: {
8951020 function abortRefreshes ( ) {
8961021 refreshSkillsAborted = true ;
8971022 refreshPluginsAborted = true ;
1023+ refreshHubSkillsAborted = true ;
8981024 }
8991025
9001026 return {
9011027 skills,
9021028 skillsStatus,
1029+ hubSkills,
1030+ hubSkillsStatus,
9031031 pluginScope,
9041032 setPluginScope,
9051033 pluginConfig,
@@ -914,10 +1042,12 @@ export function createExtensionsStore(options: {
9141042 sidebarPluginStatus,
9151043 isPluginInstalledByName,
9161044 refreshSkills,
1045+ refreshHubSkills,
9171046 refreshPlugins,
9181047 addPlugin,
9191048 importLocalSkill,
9201049 installSkillCreator,
1050+ installHubSkill,
9211051 revealSkillsFolder,
9221052 uninstallSkill,
9231053 readSkill,
0 commit comments