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

50
lib/tools/context-test.ts Normal file
View File

@@ -0,0 +1,50 @@
/**
* context_test — Debug tool to test context detection.
*
* Call this from different contexts (DM, group, via another agent) to see
* what context is detected and what guardrails are generated.
*/
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
import { jsonResult } from "openclaw/plugin-sdk";
import type { ToolContext } from "../types.js";
import { detectContext, generateGuardrails } from "../context-guard.js";
export function createContextTestTool(api: OpenClawPluginApi) {
return (ctx: ToolContext) => ({
name: "context_test",
label: "Context Test (Debug)",
description:
"Debug tool: Shows detected context and guardrails. Use this to verify context detection works correctly in different scenarios (DM, group, via another agent).",
parameters: {
type: "object",
properties: {},
},
async execute(_id: string, _params: Record<string, unknown>) {
const devClawAgentIds =
((api.pluginConfig as Record<string, unknown>)?.devClawAgentIds as
| string[]
| undefined) ?? [];
const context = await detectContext(ctx, devClawAgentIds);
const guardrails = generateGuardrails(context);
return jsonResult({
success: true,
debug: {
toolContext: {
agentId: ctx.agentId,
messageChannel: ctx.messageChannel,
sessionKey: ctx.sessionKey,
workspaceDir: ctx.workspaceDir,
agentAccountId: ctx.agentAccountId,
sandboxed: ctx.sandboxed,
},
devClawAgentIds,
},
detectedContext: context,
guardrails,
});
},
});
}