mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-17 16:12:21 -06:00
fa03d9b913
* refactor: consolidate coercion helpers * fix: remove duplicate coercion imports * fix: preserve serialized coercion guard * chore: ratchet coercion helper carve-outs * fix(test): keep gauntlet subprocess startup lean * fix: preserve imported session timestamp semantics * fix: preserve catalog timestamp string semantics * chore: align plugin SDK surface ratchet * fix: preserve trajectory and SDK string contracts * fix(test): preserve QA record assertion semantics * fix: complete standalone record guard rename * refactor(cron): use canonical string coercion * fix(acpx): preserve Pi timestamp parsing * test(channels): adapt custody test harnesses * test(telegram): classify media harness as test support * test(acpx): split timestamp contract coverage * test(channels): support generated custody contracts * chore: ban the full coercion helper name set Extends the declaration guard to all eleven consolidated helper names and renames the cron schedule-identity readNumber wrapper to readScheduleInteger so the banned generic name cannot regrow. * fix(scripts): repair release-validation guard drift and lint cause Restores the renamed isJsonRecord guard in assertTrustedWorkflowHarness after main added isRecord call sites in parallel, and attaches the caught YAML error as the thrown error cause (preserve-caught-error was red on main). * fix: preserve Claude timestamp string semantics * fix: preserve persisted timestamp string semantics * fix: preserve date-first timestamp contracts * fix(openai): harden delegation failure formatting * chore: close coercion helper guard gaps * test(openai): model non-error delegation rejection * chore: refresh plugin SDK API contract * fix(tasks): use canonical string field reader * fix(ai): use canonical provider error field coercion * fix(browser): migrate native bootstrap coercion * docs(plugin-sdk): clarify text record export compatibility * fix(gateway): normalize approval execution identity * test(outbound): isolate message action poll harness
197 lines
6.4 KiB
TypeScript
197 lines
6.4 KiB
TypeScript
// Migrate Claude helper module supports config behavior.
|
|
import {
|
|
applyMigrationConfigPatchItem,
|
|
applyMigrationManualItem,
|
|
createMigrationConfigPatchItem,
|
|
createMigrationManualItem,
|
|
hasMigrationConfigPatchConflict,
|
|
MIGRATION_REASON_TARGET_EXISTS,
|
|
} from "openclaw/plugin-sdk/migration";
|
|
import type { MigrationItem, MigrationProviderContext } from "openclaw/plugin-sdk/plugin-entry";
|
|
import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
import { childRecord, readJsonObject, sanitizeName } from "./helpers.js";
|
|
import type { ClaudeSource } from "./source.js";
|
|
|
|
type MappedMcpSource = {
|
|
sourceId: string;
|
|
sourceLabel: string;
|
|
sourcePath: string;
|
|
servers: Record<string, unknown>;
|
|
};
|
|
|
|
function mapMcpServers(raw: unknown): Record<string, unknown> | undefined {
|
|
if (!isRecord(raw)) {
|
|
return undefined;
|
|
}
|
|
const mapped: Record<string, unknown> = {};
|
|
for (const [name, value] of Object.entries(raw)) {
|
|
if (!name.trim() || !isRecord(value)) {
|
|
continue;
|
|
}
|
|
const next: Record<string, unknown> = {};
|
|
for (const key of [
|
|
"command",
|
|
"args",
|
|
"env",
|
|
"cwd",
|
|
"workingDirectory",
|
|
"url",
|
|
"type",
|
|
"transport",
|
|
"headers",
|
|
"connectionTimeoutMs",
|
|
]) {
|
|
if (value[key] !== undefined) {
|
|
next[key] = value[key];
|
|
}
|
|
}
|
|
if (Object.keys(next).length > 0) {
|
|
mapped[name] = next;
|
|
}
|
|
}
|
|
return Object.keys(mapped).length > 0 ? mapped : undefined;
|
|
}
|
|
|
|
async function collectMcpSources(source: ClaudeSource): Promise<MappedMcpSource[]> {
|
|
const sources: MappedMcpSource[] = [];
|
|
const projectMcp = await readJsonObject(source.projectMcpPath);
|
|
const projectServers = mapMcpServers(projectMcp.mcpServers ?? projectMcp);
|
|
if (projectServers && source.projectMcpPath) {
|
|
sources.push({
|
|
sourceId: "project-mcp",
|
|
sourceLabel: "project .mcp.json",
|
|
sourcePath: source.projectMcpPath,
|
|
servers: projectServers,
|
|
});
|
|
}
|
|
|
|
const claudeJson = await readJsonObject(source.userClaudeJsonPath);
|
|
const userServers = mapMcpServers(claudeJson.mcpServers);
|
|
if (userServers && source.userClaudeJsonPath) {
|
|
sources.push({
|
|
sourceId: "user-claude-json",
|
|
sourceLabel: "user ~/.claude.json",
|
|
sourcePath: source.userClaudeJsonPath,
|
|
servers: userServers,
|
|
});
|
|
}
|
|
|
|
if (source.projectDir) {
|
|
const projectRecord = childRecord(childRecord(claudeJson, "projects"), source.projectDir);
|
|
const projectScopedServers = mapMcpServers(projectRecord.mcpServers);
|
|
if (projectScopedServers && source.userClaudeJsonPath) {
|
|
sources.push({
|
|
sourceId: "user-claude-json-project",
|
|
sourceLabel: "project entry in ~/.claude.json",
|
|
sourcePath: source.userClaudeJsonPath,
|
|
servers: projectScopedServers,
|
|
});
|
|
}
|
|
}
|
|
|
|
const desktopConfig = await readJsonObject(source.desktopConfigPath);
|
|
const desktopServers = mapMcpServers(desktopConfig.mcpServers);
|
|
if (desktopServers && source.desktopConfigPath) {
|
|
sources.push({
|
|
sourceId: "desktop",
|
|
sourceLabel: "Claude Desktop config",
|
|
sourcePath: source.desktopConfigPath,
|
|
servers: desktopServers,
|
|
});
|
|
}
|
|
return sources;
|
|
}
|
|
|
|
export async function buildConfigItems(params: {
|
|
ctx: MigrationProviderContext;
|
|
source: ClaudeSource;
|
|
}): Promise<MigrationItem[]> {
|
|
const items: MigrationItem[] = [];
|
|
const mcpSources = await collectMcpSources(params.source);
|
|
const counts = new Map<string, number>();
|
|
for (const mcpSource of mcpSources) {
|
|
for (const name of Object.keys(mcpSource.servers)) {
|
|
counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
}
|
|
}
|
|
for (const mcpSource of mcpSources) {
|
|
for (const [name, value] of Object.entries(mcpSource.servers)) {
|
|
const patch = { [name]: value };
|
|
const duplicate = (counts.get(name) ?? 0) > 1;
|
|
const conflict =
|
|
duplicate ||
|
|
(!params.ctx.overwrite &&
|
|
hasMigrationConfigPatchConflict(params.ctx.config, ["mcp", "servers"], patch));
|
|
items.push(
|
|
createMigrationConfigPatchItem({
|
|
id: `config:mcp-server:${sanitizeName(mcpSource.sourceId)}:${sanitizeName(name)}`,
|
|
source: mcpSource.sourcePath,
|
|
target: `mcp.servers.${name}`,
|
|
path: ["mcp", "servers"],
|
|
value: patch,
|
|
message: `Import Claude MCP server "${name}" from ${mcpSource.sourceLabel}.`,
|
|
conflict,
|
|
reason: duplicate
|
|
? `multiple Claude MCP sources define "${name}"`
|
|
: MIGRATION_REASON_TARGET_EXISTS,
|
|
details: { sourceLabel: mcpSource.sourceLabel },
|
|
}),
|
|
);
|
|
}
|
|
}
|
|
|
|
for (const settingsPath of [
|
|
params.source.userSettingsPath,
|
|
params.source.userLocalSettingsPath,
|
|
params.source.projectSettingsPath,
|
|
params.source.projectLocalSettingsPath,
|
|
]) {
|
|
const settings = await readJsonObject(settingsPath);
|
|
if (settingsPath && settings.hooks !== undefined) {
|
|
items.push(
|
|
createMigrationManualItem({
|
|
id: `manual:hooks:${sanitizeName(settingsPath)}`,
|
|
source: settingsPath,
|
|
message: "Claude hooks were found but are not enabled automatically.",
|
|
recommendation: "Review hook commands before recreating equivalent OpenClaw automation.",
|
|
}),
|
|
);
|
|
}
|
|
if (settingsPath && settings.permissions !== undefined) {
|
|
items.push(
|
|
createMigrationManualItem({
|
|
id: `manual:permissions:${sanitizeName(settingsPath)}`,
|
|
source: settingsPath,
|
|
message: "Claude permission settings were found but are not translated automatically.",
|
|
recommendation:
|
|
"Review deny and allow rules manually. Do not import broad allow rules without a policy review.",
|
|
}),
|
|
);
|
|
}
|
|
if (settingsPath && settings.env !== undefined) {
|
|
items.push(
|
|
createMigrationManualItem({
|
|
id: `manual:env:${sanitizeName(settingsPath)}`,
|
|
source: settingsPath,
|
|
message: "Claude environment defaults were found but are not copied automatically.",
|
|
recommendation:
|
|
"Move non-secret values manually and store credentials through OpenClaw credential flows.",
|
|
}),
|
|
);
|
|
}
|
|
}
|
|
|
|
return items;
|
|
}
|
|
|
|
export async function applyConfigItem(
|
|
ctx: MigrationProviderContext,
|
|
item: MigrationItem,
|
|
): Promise<MigrationItem> {
|
|
return applyMigrationConfigPatchItem(ctx, item);
|
|
}
|
|
|
|
export function applyManualItem(item: MigrationItem): MigrationItem {
|
|
return applyMigrationManualItem(item);
|
|
}
|