← Back to PRs

#21271: fix(commands): pass channel/capabilities/shell/os to runtime in commands system prompt

by evansantos open 2026-02-19 21:29 View on GitHub →
size: M
## Summary Fixes #20837 — agent not aware of communication channel in commands path. ## Problem `resolveCommandsSystemPromptBundle()` in `commands-system-prompt.ts` hardcodes `host: "unknown"`, `os: "unknown"`, `arch: "unknown"` and completely omits `channel`, `capabilities`, `channelActions`, and `shell` from the runtime params passed to `buildSystemPromptParams()`. This means when the system prompt is rebuilt for slash command handling (`/context`, `/export-session`), all channel context is lost — the agent cannot tell if a message came from Telegram, the dashboard (webchat), Discord, etc. The main chat flow (`pi-embedded-runner/run/attempt.ts`) already passes all of these correctly. ## Root Cause (Git History) The `"unknown"` values were **intentional simplifications**, not bugs: | Commit | Author | Date | Context | |--------|--------|------|---------| | `bcde09ae9` | @steipete | Jan 15 | Created `/context` command — used `"unknown"` as placeholder | | `add3afb74` | @nickvlow | Feb 16 | Created `/export-session` — copied the same pattern | | `f6111622e` | @steipete | Feb 16 | Refactored into shared `commands-system-prompt.ts`, kept placeholders | Now that `resolveCommandsSystemPromptBundle()` is a shared function, it makes sense to populate runtime fields properly. ## Changes **`src/auto-reply/reply/commands-system-prompt.ts`** - Replace hardcoded `"unknown"` with real values: `getMachineDisplayName()`, `os.type()`, `os.release()`, `os.arch()`, `detectRuntimeShell()` - Resolve `channel` via `normalizeMessageChannel(ctx.OriginatingChannel)` - Resolve `capabilities` via `resolveChannelCapabilities()` - Resolve `channelActions` via `listChannelSupportedActions()` - Handle Telegram `inlineButtons` scope (same pattern as `pi-embedded-runner`) **`src/auto-reply/reply/commands-system-prompt.test.ts`** (new) - 7 tests covering: channel present/absent, capabilities, real host/os/arch/shell values, model info **`src/auto-reply/reply/inbound-meta.test.ts`** - 4 additional tests for channel field fallback logic (`OriginatingChannel → Surface → Provider`) ## Risk **Low** — mirrors an existing, proven pattern from `pi-embedded-runner`. `buildRuntimeLine()` already handles all these fields; we are just feeding it data it expects. Backwards compatible: if channel is undefined, the Runtime line simply omits it. No schema changes, no config changes, no new dependencies. <!-- greptile_comment --> <h3>Greptile Summary</h3> Fixed agent channel awareness in slash commands (`/context`, `/export-session`) by passing actual runtime metadata instead of hardcoded `"unknown"` placeholders. The implementation correctly mirrors the proven pattern from `pi-embedded-runner/run/attempt.ts`, including: - Real host, OS, arch, and shell values - Channel detection via `normalizeMessageChannel()` - Channel capabilities resolution - Telegram inline buttons scope handling - Channel-specific message actions Test coverage includes 7 new tests validating channel presence/absence, capabilities, and runtime field correctness, plus 4 tests for channel fallback logic. One minor issue: `accountId` is hardcoded to `undefined` instead of using `params.ctx.AccountId`, which means account-specific channel capabilities won't be resolved correctly (similar to how the reference implementation uses `params.agentAccountId`). <h3>Confidence Score: 4/5</h3> - Safe to merge with minor fix needed for account-specific capabilities - The PR correctly addresses the root cause by replacing hardcoded "unknown" values with real runtime data. Implementation closely follows the proven pattern from `pi-embedded-runner/run/attempt.ts`. However, `accountId: undefined` on lines 98 and 104 should use `params.ctx.AccountId` to properly resolve account-specific channel capabilities. This is a minor issue that affects only multi-account channel configurations. - Pay attention to `src/auto-reply/reply/commands-system-prompt.ts` lines 98 and 104 - the accountId parameter needs to be fixed <sub>Last reviewed commit: 9a3d821</sub> <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs