openclaw/src/commands/agents.commands.list.ts
Bob 6a705a37f2
ACP: add persistent Discord channel and Telegram topic bindings (#34873)
* docs: add ACP persistent binding experiment plan

* docs: align ACP persistent binding spec to channel-local config

* docs: scope Telegram ACP bindings to forum topics only

* docs: lock bound /new and /reset behavior to in-place ACP reset

* ACP: add persistent discord/telegram conversation bindings

* ACP: fix persistent binding reuse and discord thread parent context

* docs: document channel-specific persistent ACP bindings

* ACP: split persistent bindings and share conversation id helpers

* ACP: defer configured binding init until preflight passes

* ACP: fix discord thread parent fallback and explicit disable inheritance

* ACP: keep bound /new and /reset in-place

* ACP: honor configured bindings in native command flows

* ACP: avoid configured fallback after runtime bind failure

* docs: refine ACP bindings experiment config examples

* acp: cut over to typed top-level persistent bindings

* ACP bindings: harden reset recovery and native command auth

* Docs: add ACP bound command auth proposal

* Tests: normalize i18n registry zh-CN assertion encoding

* ACP bindings: address review findings for reset and fallback routing

* ACP reset: gate hooks on success and preserve /new arguments

* ACP bindings: fix auth and binding-priority review findings

* Telegram ACP: gate ensure on auth and accepted messages

* ACP bindings: fix session-key precedence and unavailable handling

* ACP reset/native commands: honor fallback targets and abort on bootstrap failure

* Config schema: validate ACP binding channel and Telegram topic IDs

* Discord ACP: apply configured DM bindings to native commands

* ACP reset tails: dispatch through ACP after command handling

* ACP tails/native reset auth: fix target dispatch and restore full auth

* ACP reset detection: fallback to active ACP keys for DM contexts

* Tests: type runTurn mock input in ACP dispatch test

* ACP: dedup binding route bootstrap and reset target resolution

* reply: align ACP reset hooks with bound session key

* docs: replace personal discord ids with placeholders

* fix: add changelog entry for ACP persistent bindings (#34873) (thanks @dutifulbob)

---------

Co-authored-by: Onur <2453968+osolmaz@users.noreply.github.com>
2026-03-05 09:38:12 +01:00

136 lines
4.1 KiB
TypeScript

import { formatCliCommand } from "../cli/command-format.js";
import { listRouteBindings } from "../config/bindings.js";
import type { AgentRouteBinding } from "../config/types.js";
import { normalizeAgentId } from "../routing/session-key.js";
import type { RuntimeEnv } from "../runtime.js";
import { defaultRuntime } from "../runtime.js";
import { shortenHomePath } from "../utils.js";
import { describeBinding } from "./agents.bindings.js";
import { requireValidConfig } from "./agents.command-shared.js";
import type { AgentSummary } from "./agents.config.js";
import { buildAgentSummaries } from "./agents.config.js";
import {
buildProviderStatusIndex,
listProvidersForAgent,
summarizeBindings,
} from "./agents.providers.js";
type AgentsListOptions = {
json?: boolean;
bindings?: boolean;
};
function formatSummary(summary: AgentSummary) {
const defaultTag = summary.isDefault ? " (default)" : "";
const header =
summary.name && summary.name !== summary.id
? `${summary.id}${defaultTag} (${summary.name})`
: `${summary.id}${defaultTag}`;
const identityParts = [];
if (summary.identityEmoji) {
identityParts.push(summary.identityEmoji);
}
if (summary.identityName) {
identityParts.push(summary.identityName);
}
const identityLine = identityParts.length > 0 ? identityParts.join(" ") : null;
const identitySource =
summary.identitySource === "identity"
? "IDENTITY.md"
: summary.identitySource === "config"
? "config"
: null;
const lines = [`- ${header}`];
if (identityLine) {
lines.push(` Identity: ${identityLine}${identitySource ? ` (${identitySource})` : ""}`);
}
lines.push(` Workspace: ${shortenHomePath(summary.workspace)}`);
lines.push(` Agent dir: ${shortenHomePath(summary.agentDir)}`);
if (summary.model) {
lines.push(` Model: ${summary.model}`);
}
lines.push(` Routing rules: ${summary.bindings}`);
if (summary.routes?.length) {
lines.push(` Routing: ${summary.routes.join(", ")}`);
}
if (summary.providers?.length) {
lines.push(" Providers:");
for (const provider of summary.providers) {
lines.push(` - ${provider}`);
}
}
if (summary.bindingDetails?.length) {
lines.push(" Routing rules:");
for (const binding of summary.bindingDetails) {
lines.push(` - ${binding}`);
}
}
return lines.join("\n");
}
export async function agentsListCommand(
opts: AgentsListOptions,
runtime: RuntimeEnv = defaultRuntime,
) {
const cfg = await requireValidConfig(runtime);
if (!cfg) {
return;
}
const summaries = buildAgentSummaries(cfg);
const bindingMap = new Map<string, AgentRouteBinding[]>();
for (const binding of listRouteBindings(cfg)) {
const agentId = normalizeAgentId(binding.agentId);
const list = bindingMap.get(agentId) ?? [];
list.push(binding);
bindingMap.set(agentId, list);
}
if (opts.bindings) {
for (const summary of summaries) {
const bindings = bindingMap.get(summary.id) ?? [];
if (bindings.length > 0) {
summary.bindingDetails = bindings.map((binding) => describeBinding(binding));
}
}
}
const providerStatus = await buildProviderStatusIndex(cfg);
for (const summary of summaries) {
const bindings = bindingMap.get(summary.id) ?? [];
const routes = summarizeBindings(cfg, bindings);
if (routes.length > 0) {
summary.routes = routes;
} else if (summary.isDefault) {
summary.routes = ["default (no explicit rules)"];
}
const providerLines = listProvidersForAgent({
summaryIsDefault: summary.isDefault,
cfg,
bindings,
providerStatus,
});
if (providerLines.length > 0) {
summary.providers = providerLines;
}
}
if (opts.json) {
runtime.log(JSON.stringify(summaries, null, 2));
return;
}
const lines = ["Agents:", ...summaries.map(formatSummary)];
lines.push("Routing rules map channel/account/peer to an agent. Use --bindings for full rules.");
lines.push(
`Channel status reflects local config/creds. For live health: ${formatCliCommand("openclaw channels status --probe")}.`,
);
runtime.log(lines.join("\n"));
}