#21271: fix(commands): pass channel/capabilities/shell/os to runtime in commands system prompt
size: M
Cluster:
Session Management and Fixes
## 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
#4878: fix: string/type handling and API fixes (#4537, #4380, #4373, #4547...
by lailoo · 2026-01-30
80.9%
#13881: fix: Address Greptile feedback - test isolation and channel resolution
by trevorgordon981 · 2026-02-11
79.1%
#8024: fix(slack): resolve channel names via directory for cross-account m...
by emma-digital-assistant · 2026-02-03
79.1%
#23320: fix(slack): respect replyToMode when incomingThreadTs is auto-created
by dorukardahan · 2026-02-22
78.6%
#12871: fix: use bash and warn about shell injection (issue #12836)
by ambicuity · 2026-02-09
78.5%
#13104: fix: persist user command message in chat transcript
by mcaxtr · 2026-02-10
78.1%
#15050: fix: transcript corruption resilience — strip aborted tool_use bloc...
by yashchitneni · 2026-02-12
78.0%
#17770: refactor(cli): reuse shared option builders
by iyoda · 2026-02-16
78.0%
#7063: fix: update callers of createSystemPromptOverride to match new API
by MohammadErfan-Jabbari · 2026-02-02
77.6%
#14488: Fix Telegram default account listing and CLI cache-write usage mapping
by abdulbb · 2026-02-12
77.6%