Files
openclaw/src/auto-reply/commands-registry.data.ts
Onur Solmaz a7d56e3554 feat: ACP thread-bound agents (#23580)
* docs: add ACP thread-bound agents plan doc

* docs: expand ACP implementation specification

* feat(acp): route ACP sessions through core dispatch and lifecycle cleanup

* feat(acp): add /acp commands and Discord spawn gate

* ACP: add acpx runtime plugin backend

* fix(subagents): defer transient lifecycle errors before announce

* Agents: harden ACP sessions_spawn and tighten spawn guidance

* Agents: require explicit ACP target for runtime spawns

* docs: expand ACP control-plane implementation plan

* ACP: harden metadata seeding and spawn guidance

* ACP: centralize runtime control-plane manager and fail-closed dispatch

* ACP: harden runtime manager and unify spawn helpers

* Commands: route ACP sessions through ACP runtime in agent command

* ACP: require persisted metadata for runtime spawns

* Sessions: preserve ACP metadata when updating entries

* Plugins: harden ACP backend registry across loaders

* ACPX: make availability probe compatible with adapters

* E2E: add manual Discord ACP plain-language smoke script

* ACPX: preserve streamed spacing across Discord delivery

* Docs: add ACP Discord streaming strategy

* ACP: harden Discord stream buffering for thread replies

* ACP: reuse shared block reply pipeline for projector

* ACP: unify streaming config and adopt coalesceIdleMs

* Docs: add temporary ACP production hardening plan

* Docs: trim temporary ACP hardening plan goals

* Docs: gate ACP thread controls by backend capabilities

* ACP: add capability-gated runtime controls and /acp operator commands

* Docs: remove temporary ACP hardening plan

* ACP: fix spawn target validation and close cache cleanup

* ACP: harden runtime dispatch and recovery paths

* ACP: split ACP command/runtime internals and centralize policy

* ACP: harden runtime lifecycle, validation, and observability

* ACP: surface runtime and backend session IDs in thread bindings

* docs: add temp plan for binding-service migration

* ACP: migrate thread binding flows to SessionBindingService

* ACP: address review feedback and preserve prompt wording

* ACPX plugin: pin runtime dependency and prefer bundled CLI

* Discord: complete binding-service migration cleanup and restore ACP plan

* Docs: add standalone ACP agents guide

* ACP: route harness intents to thread-bound ACP sessions

* ACP: fix spawn thread routing and queue-owner stall

* ACP: harden startup reconciliation and command bypass handling

* ACP: fix dispatch bypass type narrowing

* ACP: align runtime metadata to agentSessionId

* ACP: normalize session identifier handling and labels

* ACP: mark thread banner session ids provisional until first reply

* ACP: stabilize session identity mapping and startup reconciliation

* ACP: add resolved session-id notices and cwd in thread intros

* Discord: prefix thread meta notices consistently

* Discord: unify ACP/thread meta notices with gear prefix

* Discord: split thread persona naming from meta formatting

* Extensions: bump acpx plugin dependency to 0.1.9

* Agents: gate ACP prompt guidance behind acp.enabled

* Docs: remove temp experiment plan docs

* Docs: scope streaming plan to holy grail refactor

* Docs: refactor ACP agents guide for human-first flow

* Docs/Skill: add ACP feature-flag guidance and direct acpx telephone-game flow

* Docs/Skill: add OpenCode and Pi to ACP harness lists

* Docs/Skill: align ACP harness list with current acpx registry

* Dev/Test: move ACP plain-language smoke script and mark as keep

* Docs/Skill: reorder ACP harness lists with Pi first

* ACP: split control-plane manager into core/types/utils modules

* Docs: refresh ACP thread-bound agents plan

* ACP: extract dispatch lane and split manager domains

* ACP: centralize binding context and remove reverse deps

* Infra: unify system message formatting

* ACP: centralize error boundaries and session id rendering

* ACP: enforce init concurrency cap and strict meta clear

* Tests: fix ACP dispatch binding mock typing

* Tests: fix Discord thread-binding mock drift and ACP request id

* ACP: gate slash bypass and persist cleared overrides

* ACPX: await pre-abort cancel before runTurn return

* Extension: pin acpx runtime dependency to 0.1.11

* Docs: add pinned acpx install strategy for ACP extension

* Extensions/acpx: enforce strict local pinned startup

* Extensions/acpx: tighten acp-router install guidance

* ACPX: retry runtime test temp-dir cleanup

* Extensions/acpx: require proactive ACPX repair for thread spawns

* Extensions/acpx: require restart offer after acpx reinstall

* extensions/acpx: remove workspace protocol devDependency

* extensions/acpx: bump pinned acpx to 0.1.13

* extensions/acpx: sync lockfile after dependency bump

* ACPX: make runtime spawn Windows-safe

* fix: align doctor-config-flow repair tests with default-account migration (#23580) (thanks @osolmaz)
2026-02-26 11:00:09 +01:00

777 lines
21 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { listChannelDocks } from "../channels/dock.js";
import { getActivePluginRegistry } from "../plugins/runtime.js";
import { COMMAND_ARG_FORMATTERS } from "./commands-args.js";
import type {
ChatCommandDefinition,
CommandCategory,
CommandScope,
} from "./commands-registry.types.js";
import { listThinkingLevels } from "./thinking.js";
type DefineChatCommandInput = {
key: string;
nativeName?: string;
description: string;
args?: ChatCommandDefinition["args"];
argsParsing?: ChatCommandDefinition["argsParsing"];
formatArgs?: ChatCommandDefinition["formatArgs"];
argsMenu?: ChatCommandDefinition["argsMenu"];
acceptsArgs?: boolean;
textAlias?: string;
textAliases?: string[];
scope?: CommandScope;
category?: CommandCategory;
};
function defineChatCommand(command: DefineChatCommandInput): ChatCommandDefinition {
const aliases = (command.textAliases ?? (command.textAlias ? [command.textAlias] : []))
.map((alias) => alias.trim())
.filter(Boolean);
const scope =
command.scope ?? (command.nativeName ? (aliases.length ? "both" : "native") : "text");
const acceptsArgs = command.acceptsArgs ?? Boolean(command.args?.length);
const argsParsing = command.argsParsing ?? (command.args?.length ? "positional" : "none");
return {
key: command.key,
nativeName: command.nativeName,
description: command.description,
acceptsArgs,
args: command.args,
argsParsing,
formatArgs: command.formatArgs,
argsMenu: command.argsMenu,
textAliases: aliases,
scope,
category: command.category,
};
}
type ChannelDock = ReturnType<typeof listChannelDocks>[number];
function defineDockCommand(dock: ChannelDock): ChatCommandDefinition {
return defineChatCommand({
key: `dock:${dock.id}`,
nativeName: `dock_${dock.id}`,
description: `Switch to ${dock.id} for replies.`,
textAliases: [`/dock-${dock.id}`, `/dock_${dock.id}`],
category: "docks",
});
}
function registerAlias(commands: ChatCommandDefinition[], key: string, ...aliases: string[]): void {
const command = commands.find((entry) => entry.key === key);
if (!command) {
throw new Error(`registerAlias: unknown command key: ${key}`);
}
const existing = new Set(command.textAliases.map((alias) => alias.trim().toLowerCase()));
for (const alias of aliases) {
const trimmed = alias.trim();
if (!trimmed) {
continue;
}
const lowered = trimmed.toLowerCase();
if (existing.has(lowered)) {
continue;
}
existing.add(lowered);
command.textAliases.push(trimmed);
}
}
function assertCommandRegistry(commands: ChatCommandDefinition[]): void {
const keys = new Set<string>();
const nativeNames = new Set<string>();
const textAliases = new Set<string>();
for (const command of commands) {
if (keys.has(command.key)) {
throw new Error(`Duplicate command key: ${command.key}`);
}
keys.add(command.key);
const nativeName = command.nativeName?.trim();
if (command.scope === "text") {
if (nativeName) {
throw new Error(`Text-only command has native name: ${command.key}`);
}
if (command.textAliases.length === 0) {
throw new Error(`Text-only command missing text alias: ${command.key}`);
}
} else if (!nativeName) {
throw new Error(`Native command missing native name: ${command.key}`);
} else {
const nativeKey = nativeName.toLowerCase();
if (nativeNames.has(nativeKey)) {
throw new Error(`Duplicate native command: ${nativeName}`);
}
nativeNames.add(nativeKey);
}
if (command.scope === "native" && command.textAliases.length > 0) {
throw new Error(`Native-only command has text aliases: ${command.key}`);
}
for (const alias of command.textAliases) {
if (!alias.startsWith("/")) {
throw new Error(`Command alias missing leading '/': ${alias}`);
}
const aliasKey = alias.toLowerCase();
if (textAliases.has(aliasKey)) {
throw new Error(`Duplicate command alias: ${alias}`);
}
textAliases.add(aliasKey);
}
}
}
let cachedCommands: ChatCommandDefinition[] | null = null;
let cachedRegistry: ReturnType<typeof getActivePluginRegistry> | null = null;
let cachedNativeCommandSurfaces: Set<string> | null = null;
let cachedNativeRegistry: ReturnType<typeof getActivePluginRegistry> | null = null;
function buildChatCommands(): ChatCommandDefinition[] {
const commands: ChatCommandDefinition[] = [
defineChatCommand({
key: "help",
nativeName: "help",
description: "Show available commands.",
textAlias: "/help",
category: "status",
}),
defineChatCommand({
key: "commands",
nativeName: "commands",
description: "List all slash commands.",
textAlias: "/commands",
category: "status",
}),
defineChatCommand({
key: "skill",
nativeName: "skill",
description: "Run a skill by name.",
textAlias: "/skill",
category: "tools",
args: [
{
name: "name",
description: "Skill name",
type: "string",
required: true,
},
{
name: "input",
description: "Skill input",
type: "string",
captureRemaining: true,
},
],
}),
defineChatCommand({
key: "status",
nativeName: "status",
description: "Show current status.",
textAlias: "/status",
category: "status",
}),
defineChatCommand({
key: "allowlist",
description: "List/add/remove allowlist entries.",
textAlias: "/allowlist",
acceptsArgs: true,
scope: "text",
category: "management",
}),
defineChatCommand({
key: "approve",
nativeName: "approve",
description: "Approve or deny exec requests.",
textAlias: "/approve",
acceptsArgs: true,
category: "management",
}),
defineChatCommand({
key: "context",
nativeName: "context",
description: "Explain how context is built and used.",
textAlias: "/context",
acceptsArgs: true,
category: "status",
}),
defineChatCommand({
key: "export-session",
nativeName: "export-session",
description: "Export current session to HTML file with full system prompt.",
textAliases: ["/export-session", "/export"],
acceptsArgs: true,
category: "status",
args: [
{
name: "path",
description: "Output path (default: workspace)",
type: "string",
required: false,
},
],
}),
defineChatCommand({
key: "tts",
nativeName: "tts",
description: "Control text-to-speech (TTS).",
textAlias: "/tts",
category: "media",
args: [
{
name: "action",
description: "TTS action",
type: "string",
choices: [
{ value: "on", label: "On" },
{ value: "off", label: "Off" },
{ value: "status", label: "Status" },
{ value: "provider", label: "Provider" },
{ value: "limit", label: "Limit" },
{ value: "summary", label: "Summary" },
{ value: "audio", label: "Audio" },
{ value: "help", label: "Help" },
],
},
{
name: "value",
description: "Provider, limit, or text",
type: "string",
captureRemaining: true,
},
],
argsMenu: {
arg: "action",
title:
"TTS Actions:\n" +
"• On Enable TTS for responses\n" +
"• Off Disable TTS\n" +
"• Status Show current settings\n" +
"• Provider Set voice provider (edge, elevenlabs, openai)\n" +
"• Limit Set max characters for TTS\n" +
"• Summary Toggle AI summary for long texts\n" +
"• Audio Generate TTS from custom text\n" +
"• Help Show usage guide",
},
}),
defineChatCommand({
key: "whoami",
nativeName: "whoami",
description: "Show your sender id.",
textAlias: "/whoami",
category: "status",
}),
defineChatCommand({
key: "session",
nativeName: "session",
description: "Manage session-level settings (for example /session ttl).",
textAlias: "/session",
category: "session",
args: [
{
name: "action",
description: "ttl",
type: "string",
choices: ["ttl"],
},
{
name: "value",
description: "Duration (24h, 90m) or off",
type: "string",
captureRemaining: true,
},
],
argsMenu: "auto",
}),
defineChatCommand({
key: "subagents",
nativeName: "subagents",
description: "List, kill, log, spawn, or steer subagent runs for this session.",
textAlias: "/subagents",
category: "management",
args: [
{
name: "action",
description: "list | kill | log | info | send | steer | spawn",
type: "string",
choices: ["list", "kill", "log", "info", "send", "steer", "spawn"],
},
{
name: "target",
description: "Run id, index, or session key",
type: "string",
},
{
name: "value",
description: "Additional input (limit/message)",
type: "string",
captureRemaining: true,
},
],
argsMenu: "auto",
}),
defineChatCommand({
key: "acp",
nativeName: "acp",
description: "Manage ACP sessions and runtime options.",
textAlias: "/acp",
category: "management",
args: [
{
name: "action",
description:
"spawn | cancel | steer | close | sessions | status | set-mode | set | cwd | permissions | timeout | model | reset-options | doctor | install | help",
type: "string",
choices: [
"spawn",
"cancel",
"steer",
"close",
"sessions",
"status",
"set-mode",
"set",
"cwd",
"permissions",
"timeout",
"model",
"reset-options",
"doctor",
"install",
"help",
],
},
{
name: "value",
description: "Action arguments",
type: "string",
captureRemaining: true,
},
],
argsMenu: "auto",
}),
defineChatCommand({
key: "focus",
nativeName: "focus",
description: "Bind this Discord thread (or a new one) to a session target.",
textAlias: "/focus",
category: "management",
args: [
{
name: "target",
description: "Subagent label/index or session key/id/label",
type: "string",
captureRemaining: true,
},
],
}),
defineChatCommand({
key: "unfocus",
nativeName: "unfocus",
description: "Remove the current Discord thread binding.",
textAlias: "/unfocus",
category: "management",
}),
defineChatCommand({
key: "agents",
nativeName: "agents",
description: "List thread-bound agents for this session.",
textAlias: "/agents",
category: "management",
}),
defineChatCommand({
key: "kill",
nativeName: "kill",
description: "Kill a running subagent (or all).",
textAlias: "/kill",
category: "management",
args: [
{
name: "target",
description: "Label, run id, index, or all",
type: "string",
},
],
argsMenu: "auto",
}),
defineChatCommand({
key: "steer",
nativeName: "steer",
description: "Send guidance to a running subagent.",
textAlias: "/steer",
category: "management",
args: [
{
name: "target",
description: "Label, run id, or index",
type: "string",
},
{
name: "message",
description: "Steering message",
type: "string",
captureRemaining: true,
},
],
}),
defineChatCommand({
key: "config",
nativeName: "config",
description: "Show or set config values.",
textAlias: "/config",
category: "management",
args: [
{
name: "action",
description: "show | get | set | unset",
type: "string",
choices: ["show", "get", "set", "unset"],
},
{
name: "path",
description: "Config path",
type: "string",
},
{
name: "value",
description: "Value for set",
type: "string",
captureRemaining: true,
},
],
argsParsing: "none",
formatArgs: COMMAND_ARG_FORMATTERS.config,
}),
defineChatCommand({
key: "debug",
nativeName: "debug",
description: "Set runtime debug overrides.",
textAlias: "/debug",
category: "management",
args: [
{
name: "action",
description: "show | reset | set | unset",
type: "string",
choices: ["show", "reset", "set", "unset"],
},
{
name: "path",
description: "Debug path",
type: "string",
},
{
name: "value",
description: "Value for set",
type: "string",
captureRemaining: true,
},
],
argsParsing: "none",
formatArgs: COMMAND_ARG_FORMATTERS.debug,
}),
defineChatCommand({
key: "usage",
nativeName: "usage",
description: "Usage footer or cost summary.",
textAlias: "/usage",
category: "options",
args: [
{
name: "mode",
description: "off, tokens, full, or cost",
type: "string",
choices: ["off", "tokens", "full", "cost"],
},
],
argsMenu: "auto",
}),
defineChatCommand({
key: "stop",
nativeName: "stop",
description: "Stop the current run.",
textAlias: "/stop",
category: "session",
}),
defineChatCommand({
key: "restart",
nativeName: "restart",
description: "Restart OpenClaw.",
textAlias: "/restart",
category: "tools",
}),
defineChatCommand({
key: "activation",
nativeName: "activation",
description: "Set group activation mode.",
textAlias: "/activation",
category: "management",
args: [
{
name: "mode",
description: "mention or always",
type: "string",
choices: ["mention", "always"],
},
],
argsMenu: "auto",
}),
defineChatCommand({
key: "send",
nativeName: "send",
description: "Set send policy.",
textAlias: "/send",
category: "management",
args: [
{
name: "mode",
description: "on, off, or inherit",
type: "string",
choices: ["on", "off", "inherit"],
},
],
argsMenu: "auto",
}),
defineChatCommand({
key: "reset",
nativeName: "reset",
description: "Reset the current session.",
textAlias: "/reset",
acceptsArgs: true,
category: "session",
}),
defineChatCommand({
key: "new",
nativeName: "new",
description: "Start a new session.",
textAlias: "/new",
acceptsArgs: true,
category: "session",
}),
defineChatCommand({
key: "compact",
nativeName: "compact",
description: "Compact the session context.",
textAlias: "/compact",
category: "session",
args: [
{
name: "instructions",
description: "Extra compaction instructions",
type: "string",
captureRemaining: true,
},
],
}),
defineChatCommand({
key: "think",
nativeName: "think",
description: "Set thinking level.",
textAlias: "/think",
category: "options",
args: [
{
name: "level",
description: "off, minimal, low, medium, high, xhigh",
type: "string",
choices: ({ provider, model }) => listThinkingLevels(provider, model),
},
],
argsMenu: "auto",
}),
defineChatCommand({
key: "verbose",
nativeName: "verbose",
description: "Toggle verbose mode.",
textAlias: "/verbose",
category: "options",
args: [
{
name: "mode",
description: "on or off",
type: "string",
choices: ["on", "off"],
},
],
argsMenu: "auto",
}),
defineChatCommand({
key: "reasoning",
nativeName: "reasoning",
description: "Toggle reasoning visibility.",
textAlias: "/reasoning",
category: "options",
args: [
{
name: "mode",
description: "on, off, or stream",
type: "string",
choices: ["on", "off", "stream"],
},
],
argsMenu: "auto",
}),
defineChatCommand({
key: "elevated",
nativeName: "elevated",
description: "Toggle elevated mode.",
textAlias: "/elevated",
category: "options",
args: [
{
name: "mode",
description: "on, off, ask, or full",
type: "string",
choices: ["on", "off", "ask", "full"],
},
],
argsMenu: "auto",
}),
defineChatCommand({
key: "exec",
nativeName: "exec",
description: "Set exec defaults for this session.",
textAlias: "/exec",
category: "options",
args: [
{
name: "host",
description: "sandbox, gateway, or node",
type: "string",
choices: ["sandbox", "gateway", "node"],
},
{
name: "security",
description: "deny, allowlist, or full",
type: "string",
choices: ["deny", "allowlist", "full"],
},
{
name: "ask",
description: "off, on-miss, or always",
type: "string",
choices: ["off", "on-miss", "always"],
},
{
name: "node",
description: "Node id or name",
type: "string",
},
],
argsParsing: "none",
formatArgs: COMMAND_ARG_FORMATTERS.exec,
}),
defineChatCommand({
key: "model",
nativeName: "model",
description: "Show or set the model.",
textAlias: "/model",
category: "options",
args: [
{
name: "model",
description: "Model id (provider/model or id)",
type: "string",
},
],
}),
defineChatCommand({
key: "models",
nativeName: "models",
description: "List model providers or provider models.",
textAlias: "/models",
argsParsing: "none",
acceptsArgs: true,
category: "options",
}),
defineChatCommand({
key: "queue",
nativeName: "queue",
description: "Adjust queue settings.",
textAlias: "/queue",
category: "options",
args: [
{
name: "mode",
description: "queue mode",
type: "string",
choices: ["steer", "interrupt", "followup", "collect", "steer-backlog"],
},
{
name: "debounce",
description: "debounce duration (e.g. 500ms, 2s)",
type: "string",
},
{
name: "cap",
description: "queue cap",
type: "number",
},
{
name: "drop",
description: "drop policy",
type: "string",
choices: ["old", "new", "summarize"],
},
],
argsParsing: "none",
formatArgs: COMMAND_ARG_FORMATTERS.queue,
}),
defineChatCommand({
key: "bash",
description: "Run host shell commands (host-only).",
textAlias: "/bash",
scope: "text",
category: "tools",
args: [
{
name: "command",
description: "Shell command",
type: "string",
captureRemaining: true,
},
],
}),
...listChannelDocks()
.filter((dock) => dock.capabilities.nativeCommands)
.map((dock) => defineDockCommand(dock)),
];
registerAlias(commands, "whoami", "/id");
registerAlias(commands, "think", "/thinking", "/t");
registerAlias(commands, "verbose", "/v");
registerAlias(commands, "reasoning", "/reason");
registerAlias(commands, "elevated", "/elev");
registerAlias(commands, "steer", "/tell");
assertCommandRegistry(commands);
return commands;
}
export function getChatCommands(): ChatCommandDefinition[] {
const registry = getActivePluginRegistry();
if (cachedCommands && registry === cachedRegistry) {
return cachedCommands;
}
const commands = buildChatCommands();
cachedCommands = commands;
cachedRegistry = registry;
cachedNativeCommandSurfaces = null;
return commands;
}
export function getNativeCommandSurfaces(): Set<string> {
const registry = getActivePluginRegistry();
if (cachedNativeCommandSurfaces && registry === cachedNativeRegistry) {
return cachedNativeCommandSurfaces;
}
cachedNativeCommandSurfaces = new Set(
listChannelDocks()
.filter((dock) => dock.capabilities.nativeCommands)
.map((dock) => dock.id),
);
cachedNativeRegistry = registry;
return cachedNativeCommandSurfaces;
}