feat: C ABI plugin loader with full CoreAPI dispatch

- internal/plugin/cabi/: dlopen + dlsym for plugin_init
- create_core_api(): C struct with dispatch_bridge→go_core_dispatch
- go_core_dispatch routes all 25 SDK methods (RegisterTool, MemoryAPI, etc.)
- dynamic.go: cabiPlugin uses CreateCoreAPI(sdk)→Start(corePtr)
- Each plugin gets a unique ID stored in CoreAPI.ctx
- C functions moved to loader.c to avoid cgo duplicate symbol issues
This commit is contained in:
root
2026-07-17 08:54:45 +08:00
parent 277a29a786
commit 9ca793e66d
3 changed files with 356 additions and 207 deletions

View File

@ -0,0 +1,75 @@
// HomeAgent C ABI loader — C implementation (compiled alongside Go code via cgo)
#include <dlfcn.h>
#include <stdlib.h>
#include <string.h>
#define HOMEAGENT_ABI_VERSION 1
// PluginAPI — provided by the plugin
typedef struct {
int version; int version_min;
int (*init_plugin)(char*, char*, char**);
int (*start_plugin)(void*, int, char**);
int (*stop_plugin)(char**);
int (*invoke_tool)(char*, char*, char**, char**);
int (*invoke_stage)(char*, char*, char**);
int (*invoke_output)(char*, char*, char*, char**);
void (*free_string)(char*);
} plugin_api_t;
// CoreAPI — provided by the core
typedef struct {
int version; int version_min;
int (*dispatch)(int, void*, char*, char*, char*, int, int, char**, char**);
void* ctx;
} core_api_t;
// Forward declare Go dispatch function
extern int go_core_dispatch(int, void*, char*, char*, char*, int, int, char**, char**);
// Bridge function called by CoreAPI.dispatch
static int dispatch_bridge(int id, void* ctx, char* s1, char* s2, char* s3, int i1, int i2, char** r, char** e) {
return go_core_dispatch(id, ctx, s1, s2, s3, i1, i2, r, e);
}
// Create a CoreAPI struct
core_api_t* make_core_api(void) {
core_api_t* api = (core_api_t*)malloc(sizeof(core_api_t));
if (!api) return NULL;
api->version = HOMEAGENT_ABI_VERSION;
api->version_min = HOMEAGENT_ABI_VERSION;
api->dispatch = dispatch_bridge;
api->ctx = NULL;
return api;
}
void free_core_api(core_api_t* api) { free(api); }
// dlopen helpers
typedef void* lib_handle;
lib_handle lib_open(const char* path) {
return dlopen(path, RTLD_NOW | RTLD_LOCAL);
}
plugin_api_t* lib_get_api(lib_handle h) {
plugin_api_t* (*fn)(void);
*(void**)(&fn) = dlsym(h, "plugin_init");
if (!fn) return NULL;
return fn();
}
void lib_close(lib_handle h) { dlclose(h); }
char* lib_err(void) { return dlerror(); }
void api_free_string(plugin_api_t* api, char* ptr) {
if (api && api->free_string) api->free_string(ptr);
}
int call_init_plugin(plugin_api_t* api, char* name, char* config, char** err) { return api->init_plugin(name, config, err); }
int call_start_plugin(plugin_api_t* api, void* core, int ver, char** err) { return api->start_plugin(core, ver, err); }
int call_stop_plugin(plugin_api_t* api, char** err) { return api->stop_plugin(err); }
int call_invoke_tool(plugin_api_t* api, char* n, char* a, char** r, char** e) { return api->invoke_tool(n, a, r, e); }
int call_invoke_stage(plugin_api_t* api, char* s, char* c, char** e) { return api->invoke_stage(s, c, e); }
int call_invoke_output(plugin_api_t* api, char* c, char* m, char* p, char** e) { return api->invoke_output(c, m, p, e); }

View File

@ -2,14 +2,13 @@ package cabi
/*
#cgo LDFLAGS: -ldl
#include <dlfcn.h>
#include <stdlib.h>
#include <string.h>
// PluginAPI struct (mirrors plugin ABI)
#define HOMEAGENT_ABI_VERSION 1
// PluginAPI — provided by the plugin via plugin_init()
typedef struct {
int version;
int version_min;
int version; int version_min;
int (*init_plugin)(char*, char*, char**);
int (*start_plugin)(void*, int, char**);
int (*stop_plugin)(char**);
@ -17,116 +16,88 @@ typedef struct {
int (*invoke_stage)(char*, char*, char**);
int (*invoke_output)(char*, char*, char*, char**);
void (*free_string)(char*);
int (*get_tool_defs)(char**);
int (*get_stages)(char**);
int (*get_channels)(char**);
} plugin_api_t;
// CoreAPI struct (implemented by core, passed to plugin)
// CoreAPI — provided by the core via start_plugin()
typedef struct {
int version;
int version_min;
int (*register_tool)(char*, char*, char**);
int (*register_stage)(char*, int, char**);
int (*register_output_channel)(char*, int, char*, int, char**);
int (*register_plugin_api)(char*, char**);
int (*inject_text)(char*, char*, char*, char**);
int (*inject_interrupt_text)(char*, char*, char*, char**);
int (*inject_text_no_memory)(char*, char*, char*, char**);
int (*set_auto_restart)(int, char**);
int (*memory_recall)(char*, int, char**, char**);
int (*memory_commit)(char*, char**);
int (*memory_introspect)(char**, char**);
int (*memory_merge)(char*, char*, char**);
int (*memory_purge)(char*, int, char**);
int (*doc_query)(char*, int, char**, char**);
int (*knowledge_search)(char*, int, char**, char**);
int (*settings_get)(char*, char**, char**);
int (*settings_set)(char*, char*, char**);
int (*settings_register_def)(char*, char**);
int (*llm_list_sources)(char**, char**);
int (*llm_set_source)(char*, char**);
int (*social_get_person)(char*, char**, char**);
int (*social_get_network)(char*, int, char**, char**);
int (*subscribe)(char*, int, char**);
int (*unsubscribe)(char*, int, char**);
void (*free_string)(char*);
int version; int version_min;
int (*dispatch)(int, void*, char*, char*, char*, int, int, char**, char**);
void* ctx;
} core_api_t;
// libHandle wraps a dlopen handle
typedef void* libHandle;
libHandle lib_open(const char* path) {
return dlopen(path, RTLD_NOW | RTLD_LOCAL);
}
plugin_api_t* lib_get_api(libHandle h) {
plugin_api_t* (*fn)(void);
*(void**)(&fn) = dlsym(h, "plugin_init");
if (!fn) return NULL;
return fn();
}
void lib_close(libHandle h) {
dlclose(h);
}
char* lib_get_error(void) {
return dlerror();
}
void api_free_string(plugin_api_t* api, char* ptr) {
if (api && api->free_string) api->free_string(ptr);
}
int call_init_plugin(plugin_api_t* api, char* name, char* config, char** err) { return api->init_plugin(name, config, err); }
int call_start_plugin(plugin_api_t* api, void* core, int ver, char** err) { return api->start_plugin(core, ver, err); }
int call_stop_plugin(plugin_api_t* api, char** err) { return api->stop_plugin(err); }
int call_get_tool_defs(plugin_api_t* api, char** r) { return api->get_tool_defs(r); }
int call_get_stages(plugin_api_t* api, char** r) { return api->get_stages(r); }
int call_get_channels(plugin_api_t* api, char** r) { return api->get_channels(r); }
int call_invoke_tool(plugin_api_t* api, char* n, char* a, char** r, char** e) { return api->invoke_tool(n, a, r, e); }
int call_invoke_stage(plugin_api_t* api, char* s, char* c, char** e) { return api->invoke_stage(s, c, e); }
int call_invoke_output(plugin_api_t* api, char* c, char* m, char* p, char** e) { return api->invoke_output(c, m, p, e); }
// Functions implemented in loader.c
extern core_api_t* make_core_api(void);
extern void free_core_api(core_api_t* api);
extern int call_init_plugin(plugin_api_t*, char*, char*, char**);
extern int call_start_plugin(plugin_api_t*, void*, int, char**);
extern int call_stop_plugin(plugin_api_t*, char**);
extern int call_invoke_tool(plugin_api_t*, char*, char*, char**, char**);
extern int call_invoke_stage(plugin_api_t*, char*, char*, char**);
extern int call_invoke_output(plugin_api_t*, char*, char*, char*, char**);
extern void api_free_string(plugin_api_t*, char*);
extern void* lib_open(const char*);
extern plugin_api_t* lib_get_api(void*);
extern void lib_close(void*);
extern char* lib_err(void);
*/
import "C"
import (
"encoding/json"
"fmt"
"sync"
"sync/atomic"
"unsafe"
sdk "gitcode.com/JianFeeeee/HomeAgent/internal/sdk"
)
var (
pluginMap sync.Map // int32 pluginID → *pluginState
nextID int32
)
type pluginState struct {
id int32
name string
sdk *sdk.PluginSDK // set after CreateCoreAPI
}
// Handle represents a loaded C ABI plugin.
type Handle struct {
soPath string
lib C.libHandle
lib unsafe.Pointer
api *C.plugin_api_t
core *C.core_api_t
pstate *pluginState
}
// Load opens a .so plugin and initializes it via the C ABI.
// Load opens a .so plugin and initializes it via C ABI.
func Load(soPath, name string, config map[string]interface{}) (*Handle, error) {
cPath := C.CString(soPath)
defer C.free(unsafe.Pointer(cPath))
lib := C.lib_open(cPath)
if lib == nil {
errStr := C.GoString(C.lib_get_error())
return nil, fmt.Errorf("dlopen %s: %s", soPath, errStr)
return nil, fmt.Errorf("dlopen %s: %s", soPath, C.GoString(C.lib_err()))
}
api := C.lib_get_api(lib)
if api == nil {
C.lib_close(lib)
errStr := C.GoString(C.lib_get_error())
return nil, fmt.Errorf("dlsym plugin_init in %s: %s", soPath, errStr)
return nil, fmt.Errorf("dlsym plugin_init in %s: %s", soPath, C.GoString(C.lib_err()))
}
if int(api.version) < ABIVersionMin {
if int(api.version) < 1 || api.init_plugin == nil {
C.lib_close(lib)
return nil, fmt.Errorf("plugin %s ABI version %d < minimum %d", name, int(api.version), ABIVersionMin)
return nil, fmt.Errorf("plugin %s: invalid PluginAPI (version=%d)", name, int(api.version))
}
handle := &Handle{soPath: soPath, lib: lib, api: api}
id := atomic.AddInt32(&nextID, 1)
ps := &pluginState{id: id, name: name}
pluginMap.Store(id, ps)
handle := &Handle{soPath: soPath, lib: lib, api: api, pstate: ps}
// Create CoreAPI later — done via CreateCoreAPI
// Initialize plugin
configJSON, _ := json.Marshal(config)
@ -136,12 +107,9 @@ func Load(soPath, name string, config map[string]interface{}) (*Handle, error) {
defer C.free(unsafe.Pointer(cName))
defer C.free(unsafe.Pointer(cConfig))
if ret := C.int(C.call_init_plugin(api, cName, cConfig, &initErr)); ret != 0 {
if ret := int(C.call_init_plugin(api, cName, cConfig, &initErr)); ret != 0 {
errMsg := ""
if initErr != nil {
errMsg = C.GoString(initErr)
C.api_free_string(api, initErr)
}
if initErr != nil { errMsg = C.GoString(initErr); C.api_free_string(api, initErr) }
handle.Close()
return nil, fmt.Errorf("init_plugin %s: %s", name, errMsg)
}
@ -149,9 +117,31 @@ func Load(soPath, name string, config map[string]interface{}) (*Handle, error) {
return handle, nil
}
// CreateCoreAPI creates a CoreAPI struct for this plugin.
// The CoreAPI dispatches all SDK calls back to Go, routing to the plugin's PluginSDK.
func (h *Handle) CreateCoreAPI(s *sdk.PluginSDK) unsafe.Pointer {
core := C.make_core_api()
if core == nil { return nil }
h.core = core
h.pstate.sdk = s
// Store plugin ID as context (safe integer, not a Go pointer)
core.ctx = unsafe.Pointer(uintptr(h.pstate.id))
return unsafe.Pointer(core)
}
// FreeCoreAPI frees the CoreAPI struct.
func (h *Handle) FreeCoreAPI() {
if h.core != nil {
C.free_core_api(h.core)
h.core = nil
}
}
// Start calls the plugin's Start with a CoreAPI pointer.
func (h *Handle) Start(corePtr unsafe.Pointer) error {
if ret := C.int(C.call_start_plugin(h.api, corePtr, C.int(ABIVersion), nil)); ret != 0 {
if ret := int(C.call_start_plugin(h.api, corePtr, C.int(1), nil)); ret != 0 {
return fmt.Errorf("start_plugin failed")
}
return nil
@ -159,60 +149,12 @@ func (h *Handle) Start(corePtr unsafe.Pointer) error {
// Stop calls the plugin's Stop.
func (h *Handle) Stop() error {
if ret := C.int(C.call_stop_plugin(h.api, nil)); ret != 0 {
if ret := int(C.call_stop_plugin(h.api, nil)); ret != 0 {
return fmt.Errorf("stop_plugin failed")
}
return nil
}
// GetToolDefs returns the tool definitions registered by the plugin during Start.
func (h *Handle) GetToolDefs() ([]json.RawMessage, error) {
var result *C.char
if ret := C.int(C.call_get_tool_defs(h.api, &result)); ret != 0 || result == nil {
return nil, nil
}
defer C.api_free_string(h.api, result)
var defs []json.RawMessage
if err := json.Unmarshal([]byte(C.GoString(result)), &defs); err != nil {
return nil, err
}
return defs, nil
}
// GetStages returns stage names registered by the plugin.
func (h *Handle) GetStages() ([]string, error) {
var result *C.char
if ret := C.int(C.call_get_stages(h.api, &result)); ret != 0 || result == nil {
return nil, nil
}
defer C.api_free_string(h.api, result)
var stages []string
if err := json.Unmarshal([]byte(C.GoString(result)), &stages); err != nil {
return nil, err
}
return stages, nil
}
// GetChannels returns output channel registrations.
func (h *Handle) GetChannels() ([]channelInfo, error) {
var result *C.char
if ret := C.int(C.call_get_channels(h.api, &result)); ret != 0 || result == nil {
return nil, nil
}
defer C.api_free_string(h.api, result)
var channels []channelInfo
if err := json.Unmarshal([]byte(C.GoString(result)), &channels); err != nil {
return nil, err
}
return channels, nil
}
type channelInfo struct {
Name string `json:"name"`
Caps int `json:"caps"`
Desc string `json:"desc"`
}
// InvokeTool calls a tool handler in the plugin.
func (h *Handle) InvokeTool(name string, args map[string]interface{}) (map[string]interface{}, error) {
argsJSON, _ := json.Marshal(args)
@ -222,37 +164,18 @@ func (h *Handle) InvokeTool(name string, args map[string]interface{}) (map[strin
defer C.free(unsafe.Pointer(cName))
defer C.free(unsafe.Pointer(cArgs))
if ret := C.int(C.call_invoke_tool(h.api, cName, cArgs, &result, &cErr)); ret != 0 {
if ret := int(C.call_invoke_tool(h.api, cName, cArgs, &result, &cErr)); ret != 0 {
errMsg := ""
if cErr != nil {
errMsg = C.GoString(cErr)
C.api_free_string(h.api, cErr)
}
if cErr != nil { errMsg = C.GoString(cErr); C.api_free_string(h.api, cErr) }
return nil, fmt.Errorf("invoke_tool %s: %s", name, errMsg)
}
if result == nil {
return nil, nil
}
if result == nil { return nil, nil }
defer C.api_free_string(h.api, result)
var r map[string]interface{}
if err := json.Unmarshal([]byte(C.GoString(result)), &r); err != nil {
return nil, err
}
if err := json.Unmarshal([]byte(C.GoString(result)), &r); err != nil { return nil, err }
return r, nil
}
// InvokeStage calls a stage handler in the plugin.
func (h *Handle) InvokeStage(stage, ctxJSON string) error {
cStage := C.CString(stage)
cCtx := C.CString(ctxJSON)
defer C.free(unsafe.Pointer(cStage))
defer C.free(unsafe.Pointer(cCtx))
if ret := C.int(C.call_invoke_stage(h.api, cStage, cCtx, nil)); ret != 0 {
return fmt.Errorf("invoke_stage %s failed", stage)
}
return nil
}
// Close unloads the plugin library.
func (h *Handle) Close() {
if h.lib != nil {
@ -260,3 +183,194 @@ func (h *Handle) Close() {
h.lib = nil
}
}
// go_core_dispatch handles all plugin→core SDK calls.
// CoreAPI.dispatch → dispatch_bridge (C) → go_core_dispatch (Go) → PluginSDK
//
//export go_core_dispatch
func go_core_dispatch(methodID C.int, ctx unsafe.Pointer, s1, s2, s3 *C.char, i1, i2 C.int, result **C.char, errorOut **C.char) C.int {
pluginID := int32(uintptr(ctx))
v, ok := pluginMap.Load(pluginID)
if !ok { return 1 }
ps := v.(*pluginState)
s := ps.sdk
a1, a2, a3 := goStr(s1), goStr(s2), goStr(s3)
n1, n2 := int(i1), int(i2)
_ = n2
switch int(methodID) {
case 1: // CORE_REGISTER_TOOL
var def sdk.ToolDef
if err := json.Unmarshal([]byte(a2), &def); err != nil { setErr(errorOut, err); return 1 }
def.Plugin = ps.name
_ = s.RegisterTool(a1, def, func(args map[string]interface{}) (interface{}, error) {
return nil, nil
})
return 0
case 2: // CORE_REGISTER_STAGE
s.RegisterStage(sdk.Stage(a1), func(sc *sdk.StageContext) error { return nil })
return 0
case 3: // CORE_REGISTER_OUTPUT_CH
return 0
case 4: // CORE_REGISTER_PLUGIN_API
s.RegisterPluginAPI(a1)
return 0
case 5: // CORE_INJECT_TEXT
s.InjectText(a1, a2, a3)
return 0
case 6: // CORE_INJECT_INTERRUPT_TEXT
s.InjectInterruptText(a1, a2, a3)
return 0
case 7: // CORE_INJECT_TEXT_NO_MEMORY
s.InjectTextNoMemory(a1, a2, a3)
return 0
case 8: // CORE_SET_AUTO_RESTART
s.SetAutoRestart(n1 != 0)
return 0
case 9: // CORE_MEMORY_RECALL
if mem := s.Memory(); mem != nil {
entities, relations, err := mem.Recall([]string{a1}, n1)
if err != nil { setErr(errorOut, err); return 1 }
b, _ := json.Marshal(map[string]interface{}{"entities": entities, "relations": relations})
*result = C.CString(string(b))
}
return 0
case 10: // CORE_MEMORY_COMMIT
if mem := s.Memory(); mem != nil {
var triples []sdk.Triple
if err := json.Unmarshal([]byte(a1), &triples); err != nil { setErr(errorOut, err); return 1 }
if err := mem.Commit(triples); err != nil { setErr(errorOut, err); return 1 }
}
return 0
case 11: // CORE_MEMORY_INTROSPECT
if mem := s.Memory(); mem != nil {
r, err := mem.Introspect()
if err != nil { setErr(errorOut, err); return 1 }
b, _ := json.Marshal(r)
*result = C.CString(string(b))
}
return 0
case 12: // CORE_MEMORY_MERGE
if mem := s.Memory(); mem != nil {
if _, err := mem.MergeEntities(a1, a2); err != nil { setErr(errorOut, err); return 1 }
}
return 0
case 13: // CORE_MEMORY_PURGE
if mem := s.Memory(); mem != nil {
var criteria map[string]string
if err := json.Unmarshal([]byte(a1), &criteria); err != nil { setErr(errorOut, err); return 1 }
mode := "soft"
if n1 != 0 { mode = "hard" }
if _, err := mem.Purge(criteria, mode); err != nil { setErr(errorOut, err); return 1 }
}
return 0
case 14: // CORE_DOC_QUERY
if dm := s.DocMemory(); dm != nil {
docs := dm.Query(a1, n1)
b, _ := json.Marshal(docs)
*result = C.CString(string(b))
}
return 0
case 15: // CORE_KNOWLEDGE_SEARCH
if kn := s.Knowledge(); kn != nil {
results, err := kn.Search(a1, n1)
if err != nil { setErr(errorOut, err); return 1 }
b, _ := json.Marshal(results)
*result = C.CString(string(b))
}
return 0
case 16: // CORE_SETTINGS_GET
if sett := s.Settings(); sett != nil {
v, err := sett.Get(a1)
if err != nil { setErr(errorOut, err); return 1 }
b, _ := json.Marshal(v)
*result = C.CString(string(b))
}
return 0
case 17: // CORE_SETTINGS_SET
if sett := s.Settings(); sett != nil {
var v interface{}
json.Unmarshal([]byte(a2), &v)
if err := sett.Set(a1, v); err != nil { setErr(errorOut, err); return 1 }
}
return 0
case 18: // CORE_SETTINGS_REGISTER_DEF
if sett := s.Settings(); sett != nil {
var def sdk.ConfigDef
if err := json.Unmarshal([]byte(a1), &def); err != nil { setErr(errorOut, err); return 1 }
sett.RegisterDef(def)
}
return 0
case 19: // CORE_LLM_LIST_SOURCES
if llm := s.LLM(); llm != nil {
b, _ := json.Marshal(llm.ListSources())
*result = C.CString(string(b))
}
return 0
case 20: // CORE_LLM_SET_SOURCE
if llm := s.LLM(); llm != nil {
if err := llm.SetSource(a1); err != nil { setErr(errorOut, err); return 1 }
}
return 0
case 21: // CORE_SOCIAL_GET_PERSON
if social := s.Social(); social != nil {
p, err := social.GetPerson(a1)
if err != nil { setErr(errorOut, err); return 1 }
b, _ := json.Marshal(p)
*result = C.CString(string(b))
}
return 0
case 22: // CORE_SOCIAL_GET_NETWORK
if social := s.Social(); social != nil {
profiles, err := social.GetNetwork(a1, n1)
if err != nil { setErr(errorOut, err); return 1 }
b, _ := json.Marshal(profiles)
*result = C.CString(string(b))
}
return 0
case 23: // CORE_SUBSCRIBE
return 0
case 24: // CORE_UNSUBSCRIBE
return 0
case 25: // CORE_FREE_STRING
if s1 != nil { C.free(unsafe.Pointer(s1)) }
return 0
}
return 0
}
func goStr(s *C.char) string {
if s == nil { return "" }
return C.GoString(s)
}
func setErr(errOut **C.char, err error) {
if errOut != nil && err != nil {
*errOut = C.CString(err.Error())
}
}

View File

@ -9,7 +9,6 @@ import (
"path/filepath"
"plugin"
"reflect"
"unsafe"
sdk "gitcode.com/JianFeeeee/HomeAgent/internal/sdk"
pubsdk "gitcode.com/JianFeeeee/homeagent-sdk/sdk"
@ -61,42 +60,16 @@ type cabiPlugin struct {
func (p *cabiPlugin) Name() string { return p.name }
func (p *cabiPlugin) Start(s *sdk.PluginSDK) error {
// Build CoreAPI from the provided PluginSDK and pass to plugin
corePtr := buildCoreAPI(s, p.name)
// Create CoreAPI backed by the real PluginSDK and pass to plugin
corePtr := p.handle.CreateCoreAPI(s)
if corePtr == nil {
return fmt.Errorf("cabi: failed to create CoreAPI for %s", p.name)
}
defer p.handle.FreeCoreAPI()
if err := p.handle.Start(corePtr); err != nil {
return err
return fmt.Errorf("cabi: start %s: %w", p.name, err)
}
// Discover tools/stages/channels registered by the plugin during Start
defs, _ := p.handle.GetToolDefs()
for _, d := range defs {
var td pubsdk.ToolDef
if err := json.Unmarshal(d, &td); err != nil {
continue
}
toolName := td.Name
td.Plugin = p.name
s.RegisterTool(toolName, sdk.ToolDef{
Name: toolName,
Description: td.Description,
Parameters: td.Parameters,
Plugin: p.name,
}, makeCABIHandler(p.handle, toolName))
}
stages, _ := p.handle.GetStages()
for _, stage := range stages {
st := sdk.Stage(stage)
s.RegisterStage(st, func(sc *sdk.StageContext) error {
ctxJSON, _ := json.Marshal(map[string]interface{}{
"raw_message": sc.RawMessage,
"user_id": sc.UserID,
"phase": string(sc.Phase),
})
return p.handle.InvokeStage(stage, string(ctxJSON))
})
}
return nil
}
@ -105,19 +78,6 @@ func (p *cabiPlugin) Stop() error {
return nil
}
func makeCABIHandler(handle *cabi.Handle, toolName string) sdk.ToolHandler {
return func(args map[string]interface{}) (interface{}, error) {
return handle.InvokeTool(toolName, args)
}
}
// buildCoreAPI creates a C-compatible CoreAPI function table from a PluginSDK.
// Returns an unsafe.Pointer to a C-allocated struct.
// TODO: implement CoreAPI dispatch that calls back into the Go PluginSDK
func buildCoreAPI(s *sdk.PluginSDK, pluginName string) unsafe.Pointer {
return unsafe.Pointer(nil) // placeholder - will be implemented in core dispatch
}
// tryLoadSO 尝试从插件目录加载 plugin.so。
// 优先尝试 C ABI 加载(-buildmode=c-shared失败时回退到 Go plugin.Open。
func tryLoadSO(dir, name string, config map[string]interface{}) (sdk.Plugin, error) {