fix: remove all hardcoded user paths from plugins — dynamic SDK resolution
- plugins/macp/src/index.ts: use createRequire + dynamic import() for OC SDK - plugins/macp/src/acp-runtime-types.ts: local ACP runtime type definitions - plugins/macp/src/macp-runtime.ts: DEFAULT_REPO_ROOT and PI_RUNNER_PATH use os.homedir() instead of hardcoded /home/user/ - plugins/mosaic-framework/src/index.ts: removed hardcoded SDK import - No hardcoded /home/ paths remain in any plugin source file - Plugin works on any machine with openclaw installed globally
This commit is contained in:
@@ -1,18 +1,21 @@
|
||||
import { createRequire } from 'node:module';
|
||||
import * as os from 'node:os';
|
||||
import * as path from 'node:path';
|
||||
|
||||
import {
|
||||
registerAcpRuntimeBackend,
|
||||
unregisterAcpRuntimeBackend,
|
||||
} from '/home/woltjejason/.npm-global/lib/node_modules/openclaw/dist/plugin-sdk/acp-runtime.js';
|
||||
import type { OpenClawPluginApi } from '/home/woltjejason/.npm-global/lib/node_modules/openclaw/dist/plugin-sdk/index.js';
|
||||
import type {
|
||||
OpenClawPluginService,
|
||||
OpenClawPluginServiceContext,
|
||||
} from '/home/woltjejason/.npm-global/lib/node_modules/openclaw/dist/plugin-sdk/src/plugins/types.js';
|
||||
|
||||
import { MacpRuntime } from './macp-runtime.js';
|
||||
|
||||
// Resolve OC plugin SDK dynamically — works on any machine with openclaw installed globally
|
||||
const ocRequire = createRequire(import.meta.url);
|
||||
const sdkRoot = path.dirname(ocRequire.resolve('openclaw/dist/plugin-sdk/index.js'));
|
||||
|
||||
// Dynamic imports for runtime SDK functions
|
||||
const { registerAcpRuntimeBackend, unregisterAcpRuntimeBackend } = await import(
|
||||
`${sdkRoot}/acp-runtime.js`
|
||||
) as {
|
||||
registerAcpRuntimeBackend: (backend: { id: string; runtime: any; healthy: () => boolean }) => void;
|
||||
unregisterAcpRuntimeBackend: (id: string) => void;
|
||||
};
|
||||
|
||||
type PluginConfig = {
|
||||
defaultModel?: string;
|
||||
systemPrompt?: string;
|
||||
@@ -38,7 +41,7 @@ function resolveConfig(pluginConfig?: Record<string, unknown>, stateDir?: string
|
||||
const config = (pluginConfig ?? {}) as PluginConfig;
|
||||
const repoRoot = config.repoRoot?.trim()
|
||||
? path.resolve(expandHome(config.repoRoot))
|
||||
: path.resolve('/home/woltjejason/src/mosaic-stack-new');
|
||||
: path.resolve(os.homedir(), 'src', 'mosaic-stack');
|
||||
return {
|
||||
defaultModel: config.defaultModel?.trim() || 'openai/gpt-5-mini',
|
||||
systemPrompt: config.systemPrompt ?? '',
|
||||
@@ -60,12 +63,12 @@ function resolveConfig(pluginConfig?: Record<string, unknown>, stateDir?: string
|
||||
};
|
||||
}
|
||||
|
||||
function createMacpRuntimeService(pluginConfig?: Record<string, unknown>): OpenClawPluginService {
|
||||
function createMacpRuntimeService(pluginConfig?: Record<string, unknown>) {
|
||||
let runtime: MacpRuntime | null = null;
|
||||
|
||||
return {
|
||||
id: 'macp-runtime',
|
||||
async start(ctx: OpenClawPluginServiceContext) {
|
||||
async start(ctx: { stateDir: string; logger: { info: (msg: string) => void } }) {
|
||||
const resolved = resolveConfig(pluginConfig, ctx.stateDir);
|
||||
runtime = new MacpRuntime({
|
||||
...resolved,
|
||||
@@ -80,21 +83,16 @@ function createMacpRuntimeService(pluginConfig?: Record<string, unknown>): OpenC
|
||||
`macp runtime backend registered (defaultRuntime: ${resolved.defaultRuntime}, defaultDispatch: ${resolved.defaultDispatch}, timeoutMs: ${resolved.timeoutMs})`,
|
||||
);
|
||||
},
|
||||
async stop(_ctx: OpenClawPluginServiceContext) {
|
||||
unregisterAcpRuntimeBackend('macp');
|
||||
runtime = null;
|
||||
async stop() {
|
||||
if (runtime) {
|
||||
unregisterAcpRuntimeBackend('macp');
|
||||
runtime = null;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const plugin = {
|
||||
id: 'macp',
|
||||
name: 'MACP Runtime',
|
||||
description:
|
||||
'ACP runtime backend that dispatches OpenClaw oneshot sessions through the MACP controller queue.',
|
||||
register(api: OpenClawPluginApi) {
|
||||
api.registerService(createMacpRuntimeService(api.pluginConfig));
|
||||
},
|
||||
};
|
||||
|
||||
export default plugin;
|
||||
export default function register(api: any) {
|
||||
const service = createMacpRuntimeService(api.pluginConfig);
|
||||
api.registerService(service);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user