feat: enhance role-tier structure for models and update related configurations

This commit is contained in:
Lauren ten Hoor
2026-02-11 01:18:13 +08:00
parent f2e71a35d8
commit b249217bc1
5 changed files with 94 additions and 22 deletions

View File

@@ -23,12 +23,25 @@ const plugin = {
properties: { properties: {
models: { models: {
type: "object", type: "object",
description: "Model mapping per developer tier", description: "Model mapping per role and tier",
properties: { properties: {
junior: { type: "string" }, dev: {
medior: { type: "string" }, type: "object",
senior: { type: "string" }, description: "Developer tier models",
qa: { type: "string" }, properties: {
junior: { type: "string" },
medior: { type: "string" },
senior: { type: "string" },
},
},
qa: {
type: "object",
description: "QA tier models",
properties: {
"qa-engineer": { type: "string" },
"manual-tester": { type: "string" },
},
},
}, },
}, },
projectExecution: { projectExecution: {

View File

@@ -130,7 +130,7 @@ export async function dispatchTask(
transitionLabel, pluginConfig, transitionLabel, pluginConfig,
} = opts; } = opts;
const model = resolveTierToModel(tier, pluginConfig); const model = resolveTierToModel(tier, pluginConfig, role);
const worker = getWorker(project, role); const worker = getWorker(project, role);
const existingSessionKey = getSessionForTier(worker, tier); const existingSessionKey = getSessionForTier(worker, tier);
const sessionAction = existingSessionKey ? "send" : "spawn"; const sessionAction = existingSessionKey ? "send" : "spawn";

View File

@@ -5,13 +5,30 @@
*/ */
import fs from "node:fs/promises"; import fs from "node:fs/promises";
import path from "node:path"; import path from "node:path";
import type { Tier } from "../tiers.js"; import { DEV_TIERS, QA_TIERS, type Tier } from "../tiers.js";
import { HEARTBEAT_DEFAULTS } from "../services/heartbeat.js"; import { HEARTBEAT_DEFAULTS } from "../services/heartbeat.js";
function openclawConfigPath(): string { function openclawConfigPath(): string {
return path.join(process.env.HOME ?? "/home/lauren", ".openclaw", "openclaw.json"); return path.join(process.env.HOME ?? "/home/lauren", ".openclaw", "openclaw.json");
} }
/**
* Convert flat tier map to nested role-tier structure.
*/
function buildRoleTierModels(models: Record<Tier, string>): { dev: Record<string, string>; qa: Record<string, string> } {
const dev: Record<string, string> = {};
const qa: Record<string, string> = {};
for (const tier of DEV_TIERS) {
dev[tier] = models[tier];
}
for (const tier of QA_TIERS) {
qa[tier] = models[tier];
}
return { dev, qa };
}
/** /**
* Write DevClaw model tier config and devClawAgentIds to openclaw.json plugins section. * Write DevClaw model tier config and devClawAgentIds to openclaw.json plugins section.
* *
@@ -30,7 +47,7 @@ export async function writePluginConfig(
const config = JSON.parse(await fs.readFile(configPath, "utf-8")); const config = JSON.parse(await fs.readFile(configPath, "utf-8"));
ensurePluginStructure(config); ensurePluginStructure(config);
config.plugins.entries.devclaw.config.models = { ...models }; config.plugins.entries.devclaw.config.models = buildRoleTierModels(models);
if (projectExecution) { if (projectExecution) {
config.plugins.entries.devclaw.config.projectExecution = projectExecution; config.plugins.entries.devclaw.config.projectExecution = projectExecution;

View File

@@ -6,7 +6,7 @@
*/ */
export const DEV_TIERS = ["junior", "medior", "senior"] as const; export const DEV_TIERS = ["junior", "medior", "senior"] as const;
export const QA_TIERS = ["qa"] as const; export const QA_TIERS = ["qa-engineer", "manual-tester"] as const;
export const ALL_TIERS = [...DEV_TIERS, ...QA_TIERS] as const; export const ALL_TIERS = [...DEV_TIERS, ...QA_TIERS] as const;
export type DevTier = (typeof DEV_TIERS)[number]; export type DevTier = (typeof DEV_TIERS)[number];
@@ -17,7 +17,21 @@ export const DEFAULT_MODELS: Record<Tier, string> = {
junior: "anthropic/claude-haiku-4-5", junior: "anthropic/claude-haiku-4-5",
medior: "anthropic/claude-sonnet-4-5", medior: "anthropic/claude-sonnet-4-5",
senior: "anthropic/claude-opus-4-5", senior: "anthropic/claude-opus-4-5",
qa: "anthropic/claude-sonnet-4-5", "qa-engineer": "anthropic/claude-sonnet-4-5",
"manual-tester": "anthropic/claude-haiku-4-5",
};
/** Default models by role-tier structure. */
export const DEFAULT_MODELS_BY_ROLE = {
dev: {
junior: "anthropic/claude-haiku-4-5",
medior: "anthropic/claude-sonnet-4-5",
senior: "anthropic/claude-opus-4-5",
},
qa: {
"qa-engineer": "anthropic/claude-sonnet-4-5",
"manual-tester": "anthropic/claude-haiku-4-5",
},
}; };
/** Emoji used in announcements per tier. */ /** Emoji used in announcements per tier. */
@@ -25,7 +39,8 @@ export const TIER_EMOJI: Record<Tier, string> = {
junior: "⚡", junior: "⚡",
medior: "🔧", medior: "🔧",
senior: "🧠", senior: "🧠",
qa: "🔍", "qa-engineer": "🔍",
"manual-tester": "👀",
}; };
/** Check if a string is a valid tier name. */ /** Check if a string is a valid tier name. */
@@ -42,16 +57,31 @@ export function isDevTier(value: string): value is DevTier {
* Resolve a tier name to a full model ID. * Resolve a tier name to a full model ID.
* *
* Resolution order: * Resolution order:
* 1. Plugin config `models` map (user overrides) * 1. Plugin config `models.<role>.<tier>` nested structure (user overrides)
* 2. DEFAULT_MODELS (hardcoded defaults) * 2. Plugin config `models.<tier>` flat structure (backward compatibility)
* 3. Treat input as raw model ID (passthrough for non-tier values) * 3. DEFAULT_MODELS (hardcoded defaults)
* 4. Treat input as raw model ID (passthrough for non-tier values)
*/ */
export function resolveTierToModel( export function resolveTierToModel(
tier: string, tier: string,
pluginConfig?: Record<string, unknown>, pluginConfig?: Record<string, unknown>,
role?: "dev" | "qa",
): string { ): string {
const models = (pluginConfig as { models?: Record<string, string> })?.models; const models = (pluginConfig as { models?: Record<string, unknown> })?.models;
return models?.[tier] ?? DEFAULT_MODELS[tier as Tier] ?? tier;
// Try nested role-tier structure first
if (role && models && typeof models === "object") {
const roleModels = models[role] as Record<string, string> | undefined;
if (roleModels?.[tier]) return roleModels[tier];
}
// Fall back to flat structure for backward compatibility
if (models && typeof models === "object") {
const flatModel = (models as Record<string, string>)[tier];
if (flatModel) return flatModel;
}
return DEFAULT_MODELS[tier as Tier] ?? tier;
} }
/** /**
@@ -62,5 +92,6 @@ export const TIER_MIGRATION: Record<string, string> = {
haiku: "junior", haiku: "junior",
sonnet: "medior", sonnet: "medior",
opus: "senior", opus: "senior",
grok: "qa", grok: "qa-engineer",
qa: "qa-engineer",
}; };

View File

@@ -22,12 +22,23 @@ export function createSetupTool(api: OpenClawPluginApi) {
channelBinding: { type: "string", enum: ["telegram", "whatsapp"], description: "Channel to bind (optional, with newAgentName only)." }, channelBinding: { type: "string", enum: ["telegram", "whatsapp"], description: "Channel to bind (optional, with newAgentName only)." },
migrateFrom: { type: "string", description: "Agent ID to migrate channel binding from. Check openclaw.json bindings first." }, migrateFrom: { type: "string", description: "Agent ID to migrate channel binding from. Check openclaw.json bindings first." },
models: { models: {
type: "object", description: "Model overrides per tier.", type: "object", description: "Model overrides per role and tier.",
properties: { properties: {
junior: { type: "string", description: `Default: ${DEFAULT_MODELS.junior}` }, dev: {
medior: { type: "string", description: `Default: ${DEFAULT_MODELS.medior}` }, type: "object", description: "Developer tier models",
senior: { type: "string", description: `Default: ${DEFAULT_MODELS.senior}` }, properties: {
qa: { type: "string", description: `Default: ${DEFAULT_MODELS.qa}` }, junior: { type: "string", description: `Default: ${DEFAULT_MODELS.junior}` },
medior: { type: "string", description: `Default: ${DEFAULT_MODELS.medior}` },
senior: { type: "string", description: `Default: ${DEFAULT_MODELS.senior}` },
},
},
qa: {
type: "object", description: "QA tier models",
properties: {
"qa-engineer": { type: "string", description: `Default: ${DEFAULT_MODELS["qa-engineer"]}` },
"manual-tester": { type: "string", description: `Default: ${DEFAULT_MODELS["manual-tester"]}` },
},
},
}, },
}, },
projectExecution: { type: "string", enum: ["parallel", "sequential"], description: "Project execution mode. Default: parallel." }, projectExecution: { type: "string", enum: ["parallel", "sequential"], description: "Project execution mode. Default: parallel." },