feat: Implement context detection and onboarding tools for DevClaw

- Add context-guard.ts to detect interaction context (via-agent, direct, group) and generate guardrails.
- Introduce onboarding.ts for conversational onboarding context templates and workspace file checks.
- Enhance setup.ts to support new agent creation with channel binding and migration of existing bindings.
- Create analyze-channel-bindings.ts to analyze channel availability and detect binding conflicts.
- Implement context-test.ts for debugging context detection.
- Develop devclaw_onboard.ts for explicit onboarding tool that guides users through setup.
- Update devclaw_setup.ts to include channel binding and migration support in setup process.
- Modify project-register.ts to enforce project registration from group context and auto-populate group ID.
- Enhance queue-status.ts to provide context-aware status checks and recommendations.
- Update task tools (task-complete, task-create, task-pickup) to clarify group ID usage for Telegram/WhatsApp.
This commit is contained in:
Lauren ten Hoor
2026-02-09 18:34:45 +08:00
parent 32eb079521
commit a9a3fc3f1f
18 changed files with 1532 additions and 44 deletions

View File

@@ -0,0 +1,85 @@
/**
* devclaw_onboard — Explicit tool for triggering DevClaw onboarding.
*
* Provides discoverable, tool-based onboarding that doesn't rely on
* keyword detection. Returns conversational context as a tool result.
*/
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
import { jsonResult } from "openclaw/plugin-sdk";
import type { ToolContext } from "../types.js";
import {
isPluginConfigured,
hasWorkspaceFiles,
buildOnboardToolContext,
buildReconfigContext,
} from "../onboarding.js";
import { detectContext, generateGuardrails } from "../context-guard.js";
export function createOnboardTool(api: OpenClawPluginApi) {
return (ctx: ToolContext) => ({
name: "devclaw_onboard",
label: "DevClaw Onboarding",
description:
"Start DevClaw onboarding workflow. Use this tool when the user wants to: set up DevClaw, install DevClaw, onboard DevClaw, configure DevClaw, get started with DevClaw, or asks questions like 'can we install devclaw?', 'how do I set up devclaw?', 'let's onboard devclaw'. Returns step-by-step QA-style guidance. Call this FIRST before calling devclaw_setup to provide conversational setup experience.",
parameters: {
type: "object",
properties: {
mode: {
type: "string",
enum: ["first-run", "reconfigure"],
description:
"Whether this is first-time setup (first-run) or reconfiguration (reconfigure). Auto-detected if omitted.",
},
},
},
async execute(_id: string, params: Record<string, unknown>) {
// --- Context detection ---
const devClawAgentIds =
((api.pluginConfig as Record<string, unknown>)?.devClawAgentIds as
| string[]
| undefined) ?? [];
const context = await detectContext(ctx, devClawAgentIds);
// Warn if called in wrong context (group chat)
if (context.type === "group") {
return jsonResult({
success: false,
error: "DevClaw onboarding should not be done in project group chats.",
recommendation:
"Please discuss DevClaw setup in a direct message with the DevClaw agent or via another agent (like your main assistant).",
contextGuidance: generateGuardrails(context),
});
}
const configured = isPluginConfigured(
api.pluginConfig as Record<string, unknown>,
);
const hasWorkspace = await hasWorkspaceFiles(ctx.workspaceDir);
const mode = params.mode
? (params.mode as "first-run" | "reconfigure")
: configured && hasWorkspace
? "reconfigure"
: "first-run";
const instructions =
mode === "first-run"
? buildOnboardToolContext()
: buildReconfigContext(api.pluginConfig as Record<string, unknown>);
return jsonResult({
success: true,
mode,
configured,
instructions,
contextGuidance: generateGuardrails(context),
nextSteps: [
"Follow the instructions above",
"Call devclaw_setup with your collected answers",
mode === "first-run" ? "Optional: register a project afterward" : null,
].filter(Boolean),
});
},
});
}