Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions defaults/devclaw/prompts/orchestrator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Orchestrator Instructions

You are the DevClaw orchestrator.

- Use DevClaw tools to manage the workflow.
- Plan, triage, and delegate, but do not implement code changes directly.
- Prefer deterministic tool actions over ad hoc coordination.
- Keep responses concise, clear, and grounded in the current project context.
98 changes: 96 additions & 2 deletions lib/dispatch/bootstrap-hook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
*/
import { describe, it } from "node:test";
import assert from "node:assert";
import { parseDevClawSessionKey, loadRoleInstructions } from "./bootstrap-hook.js";
import { DEFAULT_ROLE_INSTRUCTIONS } from "../setup/templates.js";
import {
isMainOrchestratorSession,
parseDevClawSessionKey,
parseMainOrchestratorSessionScope,
loadOrchestratorInstructions,
loadRoleInstructions,
} from "./bootstrap-hook.js";
import { DEFAULT_ORCHESTRATOR_INSTRUCTIONS, DEFAULT_ROLE_INSTRUCTIONS } from "../setup/templates.js";
import fs from "node:fs/promises";
import path from "node:path";
import os from "node:os";
Expand Down Expand Up @@ -57,6 +63,56 @@ describe("parseDevClawSessionKey", () => {
});
});

describe("parseMainOrchestratorSessionScope", () => {
it("should parse a real telegram topic session scope", () => {
assert.deepStrictEqual(
parseMainOrchestratorSessionScope("agent:devclaw:telegram:group:-1003581929219:topic:190"),
{ channel: "telegram", channelId: "-1003581929219", messageThreadId: "190" },
);
});

it("should parse a chat-backed orchestrator session without a topic", () => {
assert.deepStrictEqual(
parseMainOrchestratorSessionScope("agent:devclaw:discord:channel:ops-room"),
{ channel: "discord", channelId: "ops-room" },
);
});

it("should reject legacy main and unknown session shapes", () => {
assert.strictEqual(parseMainOrchestratorSessionScope("agent:devclaw:main"), null);
assert.strictEqual(parseMainOrchestratorSessionScope("agent:devclaw:foo:bar"), null);
});
});

describe("isMainOrchestratorSession", () => {
it("should recognize the legacy main session key", () => {
assert.strictEqual(isMainOrchestratorSession("agent:devclaw:main"), true);
});

it("should recognize the legacy nested main session key", () => {
assert.strictEqual(isMainOrchestratorSession("agent:main:main"), true);
});

it("should recognize real telegram group orchestrator sessions", () => {
assert.strictEqual(
isMainOrchestratorSession("agent:devclaw:telegram:group:-1003581929219:topic:190"),
true,
);
});

it("should reject worker subagent sessions", () => {
assert.strictEqual(
isMainOrchestratorSession("agent:devclaw:subagent:devclaw-developer-medior-cami"),
false,
);
});

it("should reject unknown non-main session shapes", () => {
assert.strictEqual(isMainOrchestratorSession("agent:devclaw:orchestrator"), false);
assert.strictEqual(isMainOrchestratorSession("agent:devclaw:foo:bar"), false);
});
});

describe("loadRoleInstructions", () => {
it("should load project-specific instructions from devclaw/projects/<project>/prompts/", async () => {
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "devclaw-test-"));
Expand Down Expand Up @@ -127,3 +183,41 @@ describe("loadRoleInstructions", () => {
await fs.rm(tmpDir, { recursive: true });
});
});

describe("loadOrchestratorInstructions", () => {
it("should prefer project-specific orchestrator prompt over workspace default", async () => {
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "devclaw-test-"));
const projectDir = path.join(tmpDir, "devclaw", "projects", "test-project", "prompts");
const promptsDir = path.join(tmpDir, "devclaw", "prompts");
await fs.mkdir(projectDir, { recursive: true });
await fs.mkdir(promptsDir, { recursive: true });
await fs.writeFile(path.join(projectDir, "orchestrator.md"), "project orchestrator");
await fs.writeFile(path.join(promptsDir, "orchestrator.md"), "workspace orchestrator");

const result = await loadOrchestratorInstructions(tmpDir, "test-project");
assert.strictEqual(result, "project orchestrator");

await fs.rm(tmpDir, { recursive: true });
});

it("should fall back to workspace orchestrator prompt", async () => {
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "devclaw-test-"));
const promptsDir = path.join(tmpDir, "devclaw", "prompts");
await fs.mkdir(promptsDir, { recursive: true });
await fs.writeFile(path.join(promptsDir, "orchestrator.md"), "workspace orchestrator");

const result = await loadOrchestratorInstructions(tmpDir, "missing-project");
assert.strictEqual(result, "workspace orchestrator");

await fs.rm(tmpDir, { recursive: true });
});

it("should fall back to package default orchestrator prompt when present", async () => {
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "devclaw-test-"));

const result = await loadOrchestratorInstructions(tmpDir, "missing-project");
assert.strictEqual(result, DEFAULT_ORCHESTRATOR_INSTRUCTIONS ?? "");

await fs.rm(tmpDir, { recursive: true });
});
});
Loading