feat(migration): implement workspace layout migration and testing
- Added `migrate-layout.ts` to handle migration from old workspace layouts to the new `devclaw/` structure. - Introduced `migrate-layout.test.ts` for comprehensive tests covering various migration scenarios. - Updated `workspace.ts` to ensure default files are created post-migration, including `workflow.yaml` and role-specific prompts. - Refactored role instruction handling to accommodate new directory structure. - Enhanced project registration to scaffold prompt files in the new `devclaw/projects/<project>/prompts/` directory. - Adjusted setup tool descriptions and logic to reflect changes in file structure. - Updated templates to align with the new workflow configuration and role instructions.
This commit is contained in:
@@ -140,9 +140,9 @@ describe("models", () => {
|
||||
assert.strictEqual(models.developer.junior, "anthropic/claude-haiku-4-5");
|
||||
});
|
||||
|
||||
it("should resolve from config override", () => {
|
||||
const config = { models: { developer: { junior: "custom/model" } } };
|
||||
assert.strictEqual(resolveModel("developer", "junior", config), "custom/model");
|
||||
it("should resolve from resolved role config override", () => {
|
||||
const resolvedRole = { models: { junior: "custom/model" }, levels: ["junior", "medior", "senior"], defaultLevel: "medior", emoji: {}, completionResults: [] as string[], enabled: true };
|
||||
assert.strictEqual(resolveModel("developer", "junior", resolvedRole), "custom/model");
|
||||
});
|
||||
|
||||
it("should fall back to default", () => {
|
||||
@@ -153,23 +153,19 @@ describe("models", () => {
|
||||
assert.strictEqual(resolveModel("developer", "anthropic/claude-opus-4-6"), "anthropic/claude-opus-4-6");
|
||||
});
|
||||
|
||||
it("should resolve old config keys via aliases", () => {
|
||||
// Old config uses "mid" key — should still resolve via alias
|
||||
const config = { models: { developer: { mid: "custom/old-config-model" } } };
|
||||
assert.strictEqual(resolveModel("developer", "mid", config), "custom/old-config-model");
|
||||
// Also works when requesting the canonical name
|
||||
assert.strictEqual(resolveModel("developer", "medior", {}), "anthropic/claude-sonnet-4-5");
|
||||
it("should resolve via level aliases", () => {
|
||||
// "mid" alias maps to "medior" — should resolve to default medior model
|
||||
assert.strictEqual(resolveModel("developer", "mid"), "anthropic/claude-sonnet-4-5");
|
||||
// With explicit override in resolved config
|
||||
const resolvedRole = { models: { medior: "custom/old-config-model" }, levels: ["junior", "medior", "senior"], defaultLevel: "medior", emoji: {}, completionResults: [] as string[], enabled: true };
|
||||
assert.strictEqual(resolveModel("developer", "mid", resolvedRole), "custom/old-config-model");
|
||||
});
|
||||
|
||||
it("should resolve old role name config keys", () => {
|
||||
// Old config uses "dev" role key — should still resolve via role alias
|
||||
const config = { models: { dev: { junior: "custom/model" } } };
|
||||
assert.strictEqual(resolveModel("developer", "junior", config), "custom/model");
|
||||
});
|
||||
|
||||
it("should resolve old qa config keys", () => {
|
||||
const config = { models: { qa: { reviewer: "custom/qa-model" } } };
|
||||
assert.strictEqual(resolveModel("tester", "reviewer", config), "custom/qa-model");
|
||||
it("should resolve with resolved role overriding defaults selectively", () => {
|
||||
const resolvedRole = { models: { junior: "custom/model" }, levels: ["junior", "medior", "senior"], defaultLevel: "medior", emoji: {}, completionResults: [] as string[], enabled: true };
|
||||
assert.strictEqual(resolveModel("developer", "junior", resolvedRole), "custom/model");
|
||||
// Levels not overridden fall through to registry defaults
|
||||
assert.strictEqual(resolveModel("developer", "medior", resolvedRole), "anthropic/claude-sonnet-4-5");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -98,32 +98,21 @@ export function getAllDefaultModels(): Record<string, Record<string, string>> {
|
||||
* Resolve a level to a full model ID.
|
||||
*
|
||||
* Resolution order:
|
||||
* 1. Plugin config `models.<role>.<level>` in openclaw.json (highest precedence)
|
||||
* 2. Resolved config from config.yaml (if provided)
|
||||
* 3. Registry default model
|
||||
* 4. Passthrough (treat level as raw model ID)
|
||||
* 1. Resolved config from workflow.yaml (three-layer merge)
|
||||
* 2. Registry default model
|
||||
* 3. Passthrough (treat level as raw model ID)
|
||||
*/
|
||||
export function resolveModel(
|
||||
role: string,
|
||||
level: string,
|
||||
pluginConfig?: Record<string, unknown>,
|
||||
resolvedRole?: ResolvedRoleConfig,
|
||||
): string {
|
||||
const canonical = _canonicalLevel(role, level);
|
||||
|
||||
// 1. Plugin config override (openclaw.json) — check canonical role + old aliases
|
||||
const models = (pluginConfig as { models?: Record<string, unknown> })?.models;
|
||||
if (models && typeof models === "object") {
|
||||
// Check canonical role name, then fall back to old aliases (e.g., "dev" for "developer")
|
||||
const roleModels = (models[role] ?? models[Object.entries(_ROLE_ALIASES).find(([, v]) => v === role)?.[0] ?? ""]) as Record<string, string> | undefined;
|
||||
if (roleModels?.[canonical]) return roleModels[canonical];
|
||||
if (roleModels?.[level]) return roleModels[level];
|
||||
}
|
||||
|
||||
// 2. Resolved config (config.yaml)
|
||||
// 1. Resolved config (workflow.yaml — includes workspace + project overrides)
|
||||
if (resolvedRole?.models[canonical]) return resolvedRole.models[canonical];
|
||||
|
||||
// 3. Built-in registry default
|
||||
// 2. Built-in registry default
|
||||
return getDefaultModel(role, canonical) ?? canonical;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user