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:
Lauren ten Hoor
2026-02-15 20:19:09 +08:00
parent 89245f8ffa
commit a359ffed34
25 changed files with 1035 additions and 207 deletions

View File

@@ -57,9 +57,9 @@ describe("parseDevClawSessionKey", () => {
});
describe("loadRoleInstructions", () => {
it("should load project-specific instructions", async () => {
it("should load project-specific instructions from devclaw/projects/<project>/prompts/", async () => {
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "devclaw-test-"));
const projectDir = path.join(tmpDir, "projects", "roles", "test-project");
const projectDir = path.join(tmpDir, "devclaw", "projects", "test-project", "prompts");
await fs.mkdir(projectDir, { recursive: true });
await fs.writeFile(path.join(projectDir, "developer.md"), "# Developer Instructions\nDo the thing.");
@@ -69,11 +69,11 @@ describe("loadRoleInstructions", () => {
await fs.rm(tmpDir, { recursive: true });
});
it("should fall back to default instructions", async () => {
it("should fall back to default instructions from devclaw/prompts/", async () => {
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "devclaw-test-"));
const defaultDir = path.join(tmpDir, "projects", "roles", "default");
await fs.mkdir(defaultDir, { recursive: true });
await fs.writeFile(path.join(defaultDir, "tester.md"), "# Tester Default\nReview carefully.");
const promptsDir = path.join(tmpDir, "devclaw", "prompts");
await fs.mkdir(promptsDir, { recursive: true });
await fs.writeFile(path.join(promptsDir, "tester.md"), "# Tester Default\nReview carefully.");
const result = await loadRoleInstructions(tmpDir, "nonexistent-project", "tester");
assert.strictEqual(result, "# Tester Default\nReview carefully.");
@@ -92,16 +92,28 @@ describe("loadRoleInstructions", () => {
it("should prefer project-specific over default", async () => {
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "devclaw-test-"));
const projectDir = path.join(tmpDir, "projects", "roles", "my-project");
const defaultDir = path.join(tmpDir, "projects", "roles", "default");
await fs.mkdir(projectDir, { recursive: true });
await fs.mkdir(defaultDir, { recursive: true });
await fs.writeFile(path.join(projectDir, "developer.md"), "Project-specific instructions");
await fs.writeFile(path.join(defaultDir, "developer.md"), "Default instructions");
const projectPromptsDir = path.join(tmpDir, "devclaw", "projects", "my-project", "prompts");
const defaultPromptsDir = path.join(tmpDir, "devclaw", "prompts");
await fs.mkdir(projectPromptsDir, { recursive: true });
await fs.mkdir(defaultPromptsDir, { recursive: true });
await fs.writeFile(path.join(projectPromptsDir, "developer.md"), "Project-specific instructions");
await fs.writeFile(path.join(defaultPromptsDir, "developer.md"), "Default instructions");
const result = await loadRoleInstructions(tmpDir, "my-project", "developer");
assert.strictEqual(result, "Project-specific instructions");
await fs.rm(tmpDir, { recursive: true });
});
it("should fall back to old path for unmigrated workspaces", async () => {
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "devclaw-test-"));
const oldDir = path.join(tmpDir, "projects", "roles", "old-project");
await fs.mkdir(oldDir, { recursive: true });
await fs.writeFile(path.join(oldDir, "developer.md"), "Old layout instructions");
const result = await loadRoleInstructions(tmpDir, "old-project", "developer");
assert.strictEqual(result, "Old layout instructions");
await fs.rm(tmpDir, { recursive: true });
});
});