Skip to content

fix(discord): make /acp action use autocomplete#32762

Closed
sxu75374 wants to merge 1 commit intoopenclaw:mainfrom
sxu75374:fix/32753-acp-inline-action-autocomplete
Closed

fix(discord): make /acp action use autocomplete#32762
sxu75374 wants to merge 1 commit intoopenclaw:mainfrom
sxu75374:fix/32753-acp-inline-action-autocomplete

Conversation

@sxu75374
Copy link
Copy Markdown

@sxu75374 sxu75374 commented Mar 3, 2026

Summary\n- force arg to register with in Discord command options\n- keep static choices disabled for this arg so inline values (e.g. ) are preserved\n- add a Discord command registration test to verify uses autocomplete and no static choices\n\n## Testing\n- pnpm exec vitest run --config vitest.unit.config.ts src/discord/monitor.tool-result.accepts-guild-messages-mentionpatterns-match.test.ts\n- pnpm exec vitest run --config vitest.unit.config.ts src/auto-reply/commands-registry.test.ts\n\nFixes #32753

Use autocomplete for /acp action in Discord so inline values like '/acp close' are preserved instead of forcing the fallback picker menu.

Signed-off-by: sxu75374 <[email protected]>
@openclaw-barnacle openclaw-barnacle bot added channel: discord Channel integration: discord size: XS labels Mar 3, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 3, 2026

Greptile Summary

This PR fixes issue #32753 by forcing the /acp action Discord command option to use autocomplete instead of static choices, which allows users to type arbitrary inline values that are not in the predefined list.

Changes:

  • src/discord/monitor/native-command.ts: Adds a third condition to shouldAutocomplete that activates autocomplete for command.key === "acp" && arg.name === "action". The fix is functionally correct but introduces command-specific logic inside a generic option-builder (buildDiscordCommandOptions). A forceAutocomplete?: boolean property on CommandArgDefinition would be a more extensible solution that scales to other commands without further hardcoding.
  • src/discord/monitor.tool-result.accepts-guild-messages-mentionpatterns-match.test.ts: Adds a test to verify the action option has an autocomplete handler and no static choices. The test logic is sound, but it is placed in a file focused on mention-pattern matching. The existing ACP command tests in src/auto-reply/commands-registry.test.ts would be a better home for it.

Confidence Score: 4/5

  • Safe to merge — the fix is functionally correct and does not introduce any regressions; feedback is limited to design and test-placement style concerns.
  • The core logic change is small and correct: forcing autocomplete for the /acp action option prevents Discord from locking users to the static choice list. The existing autocomplete path in the builder is reused without modification, so there is no new runtime risk. Score is 4 rather than 5 because the hardcoded command identity in a generic builder and the misplaced test add maintainability debt worth addressing before the pattern spreads.
  • Both changed files have minor style concerns: native-command.ts for the hardcoded command key, and the test file for the misplaced test. Neither requires blocking attention for correctness.

Last reviewed commit: 110ad77

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +121 to +123
(typeof arg.choices === "function" ||
resolvedChoices.length > 25 ||
(command.key === "acp" && arg.name === "action"));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded command/arg identity in generic builder

This third condition couples a generic Discord option-building function to a specific command name ("acp") and argument name ("action"). If more commands need the same forced-autocomplete behavior in the future, you'd have to keep extending this condition with additional || clauses.

A cleaner, extensible approach would be to add a forceAutocomplete?: boolean field to CommandArgDefinition and set it on the action arg in the acp definition in commands-registry.data.ts. The condition here would then simply read:

const shouldAutocomplete =
  resolvedChoices.length > 0 &&
  (typeof arg.choices === "function" ||
    resolvedChoices.length > 25 ||
    arg.forceAutocomplete === true);

And in commands-registry.data.ts:

{
  name: "action",
  description: "Action to run",
  type: "string",
  forceAutocomplete: true,
  choices: [ "spawn", "cancel", ... ],
},

This keeps the builder generic and moves the "force autocomplete" intent to where the command is defined.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/discord/monitor/native-command.ts
Line: 121-123

Comment:
**Hardcoded command/arg identity in generic builder**

This third condition couples a generic Discord option-building function to a specific command name (`"acp"`) and argument name (`"action"`). If more commands need the same forced-autocomplete behavior in the future, you'd have to keep extending this condition with additional `||` clauses.

A cleaner, extensible approach would be to add a `forceAutocomplete?: boolean` field to `CommandArgDefinition` and set it on the `action` arg in the `acp` definition in `commands-registry.data.ts`. The condition here would then simply read:

```ts
const shouldAutocomplete =
  resolvedChoices.length > 0 &&
  (typeof arg.choices === "function" ||
    resolvedChoices.length > 25 ||
    arg.forceAutocomplete === true);
```

And in `commands-registry.data.ts`:
```ts
{
  name: "action",
  description: "Action to run",
  type: "string",
  forceAutocomplete: true,
  choices: [ "spawn", "cancel", ... ],
},
```

This keeps the builder generic and moves the "force autocomplete" intent to where the command is defined.

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +350 to +379
it("registers /acp action with autocomplete instead of static choices", () => {
const cfg = {
commands: { native: true },
channels: {
discord: { dm: { enabled: true, policy: "open" } },
},
agents: { defaults: { workspace: "/tmp/openclaw" } },
session: { store: "/tmp/openclaw-sessions.json" },
} as ReturnType<typeof import("../config/config.js").loadConfig>;

const acpSpec = listNativeCommandSpecsForConfig(cfg, { provider: "discord" }).find(
(spec) => spec.name === "acp",
);
expect(acpSpec).toBeTruthy();

const command = createDiscordNativeCommand({
command: acpSpec!,
cfg,
discordConfig: cfg.channels!.discord!,
accountId: "default",
sessionPrefix: "discord:slash",
ephemeralDefault: true,
threadBindings: createNoopThreadBindingManager("default"),
});

const actionOption = (command.options ?? []).find((option) => option.name === "action");
expect(actionOption).toBeTruthy();
expect(actionOption?.autocomplete).toBeTypeOf("function");
expect(actionOption?.choices).toBeUndefined();
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test placed in unrelated test file

This test verifies that /acp registers its action option with autocomplete rather than static choices — that is a command registration / option-building concern. The host file's name (monitor.tool-result.accepts-guild-messages-mentionpatterns-match.test.ts) describes a completely different behavior (tool-result dispatching and mention-pattern matching), and reading the surrounding tests confirms that mismatch.

The PR description even points to src/auto-reply/commands-registry.test.ts as the place where acp-related command tests live (there is already a "keeps ACP native action choices aligned with implemented handlers" test there). Placing this test alongside the existing ACP registry tests would improve discoverability and keep the file responsibilities well-scoped.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/discord/monitor.tool-result.accepts-guild-messages-mentionpatterns-match.test.ts
Line: 350-379

Comment:
**Test placed in unrelated test file**

This test verifies that `/acp` registers its `action` option with autocomplete rather than static choices — that is a command registration / option-building concern. The host file's name (`monitor.tool-result.accepts-guild-messages-mentionpatterns-match.test.ts`) describes a completely different behavior (tool-result dispatching and mention-pattern matching), and reading the surrounding tests confirms that mismatch.

The PR description even points to `src/auto-reply/commands-registry.test.ts` as the place where `acp`-related command tests live (there is already a `"keeps ACP native action choices aligned with implemented handlers"` test there). Placing this test alongside the existing ACP registry tests would improve discoverability and keep the file responsibilities well-scoped.

How can I resolve this? If you propose a fix, please make it concise.

@thewilloftheshadow
Copy link
Copy Markdown
Member

Superseded by #33136, which consolidates the /acp inline action autocomplete fix plus the bound-thread bot system message guard. Closing in favor of that PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants