Files
devclaw-gitea/lib/tools/setup.ts
Lauren ten Hoor 862813e6d3 refactor: restructure workspace file organization (#121) (#122)
## Path Changes
- audit.log: memory/audit.log → log/audit.log
- projects.json: memory/projects.json → projects/projects.json
- prompts: roles/<project>/<role>.md → projects/prompts/<project>/<role>.md

## Files Updated
- lib/audit.ts - new audit log path
- lib/projects.ts - new projects.json path
- lib/dispatch.ts - new prompt instructions path
- lib/tools/project-register.ts - prompt scaffolding path
- lib/setup/workspace.ts - workspace scaffolding paths
- lib/context-guard.ts - projects.json path
- lib/tools/setup.ts - tool description
- lib/templates.ts - AGENTS.md template path references

## Documentation Updated
- README.md
- docs/ARCHITECTURE.md
- docs/ONBOARDING.md
- docs/QA_WORKFLOW.md
- docs/ROADMAP.md
- docs/TESTING.md

Addresses issue #121
2026-02-11 01:55:26 +08:00

131 lines
4.3 KiB
TypeScript

/**
* setup — Agent-driven DevClaw setup.
*
* Creates agent, configures model tiers, writes workspace files.
* Thin wrapper around lib/setup/.
*/
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
import { jsonResult } from "openclaw/plugin-sdk";
import type { ToolContext } from "../types.js";
import { runSetup } from "../setup/index.js";
import { ALL_TIERS, DEFAULT_MODELS, type Tier } from "../tiers.js";
export function createSetupTool(api: OpenClawPluginApi) {
return (ctx: ToolContext) => ({
name: "setup",
label: "Setup",
description: `Execute DevClaw setup. Creates AGENTS.md, HEARTBEAT.md, projects/projects.json, and model tier config. Optionally creates a new agent with channel binding. Called after onboard collects configuration.`,
parameters: {
type: "object",
properties: {
newAgentName: {
type: "string",
description:
"Create a new agent. Omit to configure current workspace.",
},
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.",
},
models: {
type: "object",
description: "Model overrides per role and tier.",
properties: {
dev: {
type: "object",
description: "Developer tier models",
properties: {
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: {
reviewer: {
type: "string",
description: `Default: ${DEFAULT_MODELS.reviewer}`,
},
tester: {
type: "string",
description: `Default: ${DEFAULT_MODELS.tester}`,
},
},
},
},
},
projectExecution: {
type: "string",
enum: ["parallel", "sequential"],
description: "Project execution mode. Default: parallel.",
},
},
},
async execute(_id: string, params: Record<string, unknown>) {
const result = await runSetup({
newAgentName: params.newAgentName as string | undefined,
channelBinding:
(params.channelBinding as "telegram" | "whatsapp") ?? null,
migrateFrom: params.migrateFrom as string | undefined,
agentId: params.newAgentName ? undefined : ctx.agentId,
workspacePath: params.newAgentName ? undefined : ctx.workspaceDir,
models: params.models as Partial<Record<Tier, string>> | undefined,
projectExecution: params.projectExecution as
| "parallel"
| "sequential"
| undefined,
});
const lines = [
result.agentCreated
? `Agent "${result.agentId}" created`
: `Configured "${result.agentId}"`,
"",
];
if (result.bindingMigrated) {
lines.push(
`✅ Binding migrated: ${result.bindingMigrated.channel} (${result.bindingMigrated.from}${result.agentId})`,
"",
);
}
lines.push(
"Models:",
...ALL_TIERS.map((t) => ` ${t}: ${result.models[t]}`),
"",
"Files:",
...result.filesWritten.map((f) => ` ${f}`),
);
if (result.warnings.length > 0)
lines.push("", "Warnings:", ...result.warnings.map((w) => ` ${w}`));
lines.push(
"",
"Next: register a project, then create issues and pick them up.",
);
return jsonResult({
success: true,
...result,
summary: lines.join("\n"),
});
},
});
}