Skip to content

feat(web): surface opencode /compact and /clear in the slash command menu - #1675

Open
rzsgsfm wants to merge 1 commit into
tiann:mainfrom
rzsgsfm:fix/opencode-compact
Open

feat(web): surface opencode /compact and /clear in the slash command menu#1675
rzsgsfm wants to merge 1 commit into
tiann:mainfrom
rzsgsfm:fix/opencode-compact

Conversation

@rzsgsfm

@rzsgsfm rzsgsfm commented Aug 23, 2026

Copy link
Copy Markdown

Motivation

On the remote web/phone UI, the opencode / autocomplete menu is built from BUILTIN_SLASH_COMMANDS in shared/src/slashCommands.ts. It exposes only help / status / plan / default / init, intentionally omitting compact and clear.

That omission traces back to #753, when the OpenCode ACP backend had no compaction RPC — /compact and /clear were unsupported placeholders, so hiding them from the menu made sense.

Since then, compact became fully supported via the native OpenCode compaction bridge (#1252, + retries in #1433) and clear is a real implementation, but the menu list and the CLI test that locks the "hidden" set were never updated. The rationale for hiding them is now stale:

  • compact/clear have no composer button (unlike model/reasoning/permissions).
  • They are no longer unsupported — they work when typed manually.

So they are being surfaced in the menu, matching other flavors (pi, codex, grok, claude already list compact).

Change

  • shared/src/slashCommands.ts: add compact and clear to the opencode builtin list.
  • cli/src/modules/common/slashCommands.test.ts: move compact/clear from the "hidden" set into the expected opencode builtin list; keep model/reasoning/effort/permissions hidden (they have composer buttons / are aliases).
  • web/src/lib/codexSlashCommands.test.ts: add a web-side assertion that opencode exposes compact and clear.

Verification

  • OpenCode resolver already handles /compact (kind: 'compact') and /clear (kind: 'clear'); /help already lists /compact.
  • Updated unit expectations across cli + web for the opencode builtin set.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Findings

  • [Minor] Gate the OpenCode /clear menu entry by session origin — the shared list now advertises it for terminal-started sessions, but the runtime rejects that command unless the session is runner-backed. Evidence shared/src/slashCommands.ts:52; rejection path cli/src/opencode/runOpencode.ts:264.

    Suggested fix:

    const merged = query.data?.success && query.data.commands
        ? mergeSlashCommands([...builtin, ...query.data.commands])
        : builtin
    
    return merged.filter((command) =>
        command.source !== 'builtin'
        || agentType !== 'opencode'
        || command.name !== 'clear'
        || startedBy === 'runner'
    )

Summary

  • Review mode: initial
  • One Minor finding: make /clear availability capability-aware so terminal-started sessions do not offer a command they cannot execute.

Testing

  • Not run (automation). GitHub's test job is still in progress; integration and fixture drift checks passed. Add coverage for both runner-backed and terminal-started OpenCode command lists.

HAPI Bot

{ name: 'default', description: 'Return OpenCode permission mode to default', source: 'builtin' },
{ name: 'init', description: 'Generate or refresh AGENTS.md for this project', source: 'builtin' },
{ name: 'compact', description: 'Compact (summarize) the OpenCode session context (remote sessions only)', source: 'builtin' },
{ name: 'clear', description: 'Archive this HAPI session and open a fresh OpenCode session', source: 'builtin' },

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[MINOR] Gate /clear on runner-backed OpenCode sessions

This unconditional built-in is consumed by the web fallback and by the CLI slash-command RPC for every OpenCode session. However, cli/src/opencode/runOpencode.ts:264-275 explicitly rejects /clear when startedBy !== 'runner'. Terminal-started sessions can be handed off to remote control, so those users will now see and select a menu item that only returns an error. Thread session.metadata.startedBy (or an equivalent capability) into command enumeration and filter only the built-in row, preserving custom commands named clear.

Suggested fix:

return merged.filter((command) =>
    command.source !== 'builtin'
    || agentType !== 'opencode'
    || command.name !== 'clear'
    || startedBy === 'runner'
)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant