Compare commits
2 Commits
9cd90f7213
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| e73a7ea049 | |||
| 49af2129ae |
@@ -17,7 +17,8 @@ export type OpenAITool = {
|
|||||||
|
|
||||||
export type ClaudeDispatchOptions = {
|
export type ClaudeDispatchOptions = {
|
||||||
prompt: string;
|
prompt: string;
|
||||||
/** System prompt passed via --system-prompt on every invocation (stateless, not stored in session) */
|
/** Appended to Claude Code's built-in system prompt via --append-system-prompt on every invocation.
|
||||||
|
* Stateless: not persisted in session file, fully replaces any prior appended content on resume. */
|
||||||
systemPrompt?: string;
|
systemPrompt?: string;
|
||||||
workspace: string;
|
workspace: string;
|
||||||
agentId?: string;
|
agentId?: string;
|
||||||
@@ -97,7 +98,7 @@ export async function* dispatchToClaude(
|
|||||||
workspace,
|
workspace,
|
||||||
agentId = "",
|
agentId = "",
|
||||||
resumeSessionId,
|
resumeSessionId,
|
||||||
permissionMode = "bypassPermissions",
|
permissionMode = "default",
|
||||||
openclawTools,
|
openclawTools,
|
||||||
bridgePort = 18800,
|
bridgePort = 18800,
|
||||||
bridgeApiKey = "",
|
bridgeApiKey = "",
|
||||||
@@ -111,15 +112,15 @@ export async function* dispatchToClaude(
|
|||||||
prompt,
|
prompt,
|
||||||
"--output-format", "stream-json",
|
"--output-format", "stream-json",
|
||||||
"--verbose",
|
"--verbose",
|
||||||
"--permission-mode", permissionMode,
|
"--allowedTools", "Bash Edit Write Read Glob Grep WebFetch WebSearch NotebookEdit Monitor TodoWrite mcp__openclaw__*",
|
||||||
"--dangerously-skip-permissions",
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// --system-prompt is stateless (not persisted in session file) and fully
|
// --append-system-prompt appends to Claude Code's built-in system prompt rather
|
||||||
// replaces any prior system prompt on each invocation, including resumes.
|
// than replacing it, preserving the full agent SDK instructions (tool use behavior,
|
||||||
// We pass it every turn so skills/persona stay current.
|
// memory management, etc.). The appended bootstrap (persona + skills) is stateless:
|
||||||
|
// not persisted in the session file, takes effect every invocation including resumes.
|
||||||
if (systemPrompt) {
|
if (systemPrompt) {
|
||||||
args.push("--system-prompt", systemPrompt);
|
args.push("--append-system-prompt", systemPrompt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resumeSessionId) {
|
if (resumeSessionId) {
|
||||||
|
|||||||
@@ -321,21 +321,8 @@ export function createBridgeServer(config: BridgeServerConfig): http.Server {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the tool registration by name
|
// Build tool execution context (needed before tool lookup for factory instantiation).
|
||||||
const toolReg = pluginRegistry.tools.find((t) => t.names.includes(toolName));
|
|
||||||
if (!toolReg) {
|
|
||||||
sendJson(res, 200, { error: `Tool '${toolName}' not registered in OpenClaw plugin registry` });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build tool execution context.
|
|
||||||
// config is required by memory tools (resolveMemoryToolContext checks it).
|
|
||||||
// Read from globalThis where index.ts stores api.config on every registration.
|
|
||||||
// sessionKey must be in OpenClaw's canonical format "agent:<agentId>:<rest>" so that
|
|
||||||
// parseAgentSessionKey() can extract the agentId for memory tool context resolution.
|
|
||||||
const liveConfig = (_G["_contractorOpenClawConfig"] ?? null) as Record<string, unknown> | null;
|
const liveConfig = (_G["_contractorOpenClawConfig"] ?? null) as Record<string, unknown> | null;
|
||||||
// Construct a canonical session key so memory tools can resolve the agentId from it.
|
|
||||||
// Format: "agent:<agentId>:direct:bridge"
|
|
||||||
const canonicalSessionKey = execAgentId ? `agent:${execAgentId}:direct:bridge` : undefined;
|
const canonicalSessionKey = execAgentId ? `agent:${execAgentId}:direct:bridge` : undefined;
|
||||||
const toolCtx = {
|
const toolCtx = {
|
||||||
config: liveConfig ?? undefined,
|
config: liveConfig ?? undefined,
|
||||||
@@ -345,6 +332,28 @@ export function createBridgeServer(config: BridgeServerConfig): http.Server {
|
|||||||
sessionKey: canonicalSessionKey,
|
sessionKey: canonicalSessionKey,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Find tool by name. Some plugins register tools via factory functions without
|
||||||
|
// declaring names upfront (names array is empty). For those, instantiate the
|
||||||
|
// factory and match by the returned tool's .name property.
|
||||||
|
let toolReg = pluginRegistry.tools.find((t) => t.names.includes(toolName));
|
||||||
|
if (!toolReg) {
|
||||||
|
for (const candidate of pluginRegistry.tools) {
|
||||||
|
if (candidate.names.length > 0) continue;
|
||||||
|
try {
|
||||||
|
const inst = candidate.factory(toolCtx);
|
||||||
|
const items = Array.isArray(inst) ? inst : [inst];
|
||||||
|
if (items.some((t) => (t as { name?: string }).name === toolName)) {
|
||||||
|
toolReg = candidate;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch { /* skip */ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!toolReg) {
|
||||||
|
sendJson(res, 200, { error: `Tool '${toolName}' not registered in OpenClaw plugin registry` });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Instantiate the tool via its factory
|
// Instantiate the tool via its factory
|
||||||
const toolOrTools = toolReg.factory(toolCtx);
|
const toolOrTools = toolReg.factory(toolCtx);
|
||||||
const toolInstance = Array.isArray(toolOrTools)
|
const toolInstance = Array.isArray(toolOrTools)
|
||||||
|
|||||||
Reference in New Issue
Block a user