Skip to content

feat(domain): add messaging remote control service#512

Open
arielshad wants to merge 18 commits intomainfrom
feat/messaging-remote-control
Open

feat(domain): add messaging remote control service#512
arielshad wants to merge 18 commits intomainfrom
feat/messaging-remote-control

Conversation

@arielshad
Copy link
Copy Markdown
Contributor

Summary

  • Add TypeSpec domain models for messaging concepts (commands, config, notifications, platform enums)
  • Implement messaging service infrastructure with tunnel adapter, chat relay, command executor, content sanitizer, and notification emitter
  • Add CLI commands for messaging configuration (enable/disable, platform config, notification settings)
  • Register messaging service in DI container and integrate with _serve command daemon lifecycle

What Changed

TypeSpec Models (tsp/)

  • New enums: MessagingCommandType, MessagingFrameType, MessagingPlatform
  • New entities: MessagingCommand, MessagingConfig, MessagingPlatformConfig, MessagingNotification
  • Extended Settings model with messaging configuration

Messaging Service (packages/core/src/infrastructure/services/messaging/)

  • messaging.service.ts — Orchestrates tunnel connection, chat relay, command execution, and notifications
  • messaging-tunnel.adapter.ts — WebSocket tunnel adapter for commands-com gateway connectivity
  • chat-relay.ts — Relays chat messages between external platforms and shep sessions
  • command-executor.ts — Executes remote commands received via messaging with permission controls
  • content-sanitizer.ts — Sanitizes message content for safe handling
  • notification-emitter.ts — Emits notifications to connected messaging platforms

CLI Commands (src/presentation/cli/commands/settings/messaging.command.ts)

  • settings messaging enable/disable — Toggle messaging remote control
  • settings messaging platform — Configure platform-specific settings
  • settings messaging notifications — Configure notification preferences

Integration

  • DI container registration for messaging service and sub-components
  • _serve command integration for daemon lifecycle management

Evidence

Evidence Source
39 messaging unit tests passing (chat-relay, command-executor, content-sanitizer, notification-emitter) specs/082-messaging-remote-control/evidence/messaging-unit-tests.txt
12 serve command tests passing with messaging integration specs/082-messaging-remote-control/evidence/serve-command-tests.txt
Full test suite — 378 files, 5338 tests, zero failures specs/082-messaging-remote-control/evidence/full-unit-test-summary.txt
TypeScript build completes successfully specs/082-messaging-remote-control/evidence/build-output.txt
TypeSpec compilation succeeds for all messaging models specs/082-messaging-remote-control/evidence/tsp-compile-output.txt

Test Plan

  • All 39 messaging service unit tests pass
  • All 12 serve command tests pass (including messaging lifecycle)
  • Full unit test suite passes (5338 tests, 0 failures)
  • Build compiles without errors
  • Lint passes with zero warnings

Built with Shep 🐑 Shep Bot

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 2, 2026

🔒 Security Issues Detected

Scanner Status Details
Gitleaks ❌ Failed Secret detection in git history
Semgrep ✅ Pass SAST for TypeScript/JavaScript

⚠️ Please review the failed checks above before merging.


🤖 Generated by CI Security Scan | View Details

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 2, 2026

🔒 Security Issues Detected

Scanner Status Details
Gitleaks ❌ Failed Secret detection in git history
Semgrep ✅ Pass SAST for TypeScript/JavaScript

⚠️ Please review the failed checks above before merging.


🤖 Generated by CI Security Scan | View Details

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 2, 2026

Dev Release Published

Artifact Version Install
npm 1.163.0-pr512.9a94785 npm install -g @shepai/cli@1.163.0-pr512.9a94785

Published from commit 5ae742a | View CI

blackpc and others added 12 commits April 6, 2026 16:47
## Summary

After migrating to the Anthropic V2 SDK for interactive chat sessions,
the `permissionMode: 'bypassPermissions'` option stopped working because
the V2 API hardcodes `allowDangerouslySkipPermissions: false`. This
caused the agent to silently fall back to default permission mode,
making it unable to execute Bash commands and other tools without user
approval prompts.

**Root cause:** V2 SDK ignores `bypassPermissions` permission mode, so
all tool calls were being blocked or prompted.

**Fix:** Replace `permissionMode: 'bypassPermissions'` with the
V2-supported `allowedTools` array, which pre-approves all standard
Claude Code tools (Bash, Read, Write, Edit, Glob, Grep, Agent, etc.) at
the CLI level. `AskUserQuestion` is intentionally excluded from the
auto-allow list so it continues to be intercepted by the `canUseTool`
callback for user interaction.

## Changes

- Added `AUTO_ALLOWED_TOOLS` constant listing all 26 standard Claude
Code tools to auto-allow
- Replaced conditional `permissionMode: 'bypassPermissions'` with
unconditional `allowedTools` pass-through
- `canUseTool` callback is now only passed when `onUserQuestion` is
provided (no fallback to bypassPermissions)
- Added comprehensive unit tests (11 test cases) covering:
  - `allowedTools` is passed with all standard tools
  - `AskUserQuestion` is excluded from auto-allowed tools
  - `permissionMode` is no longer set
- `canUseTool` callback behavior for both regular tools and
`AskUserQuestion`
- Environment variable stripping, system prompt forwarding, default
model

## Test plan

- [x] Unit tests pass (11/11) for the interactive executor
- [ ] Manual verification: run `shep` interactive chat and confirm
Bash/tool execution works without permission prompts
- [ ] Verify `AskUserQuestion` still pauses for user input

Built with Shep 🐑 [Shep Bot](https://github.com/shep-ai/shep)

---------

Co-authored-by: shep-ai[bot] <bot@shep.bot>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## [1.175.1](v1.175.0...v1.175.1) (2026-04-06)

### Bug Fixes

* **agents:** use allowedtools for v2 sdk tool permissions ([#534](#534)) ([7c9c50e](7c9c50e))
Add TypeSpec models for external messaging integration via the
Commands.com Gateway: MessagingPlatform enum, MessagingCommand,
MessagingNotification, and MessagingConfig settings model.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Implement external messaging remote control via Commands.com Gateway,
enabling Telegram/WhatsApp-based notifications, commands, and chat
relay for managing Shep features remotely.

Changes:
- IMessagingService port interface for clean architecture boundary
- MessagingTunnelAdapter: WebSocket tunnel to Gateway with heartbeat
  and auto-reconnect
- MessagingCommandExecutor: maps /new, /approve, /reject, /stop,
  /resume, /status commands to existing use cases
- MessagingNotificationEmitter: subscribes to NotificationEventBus,
  debounces and sanitizes events before forwarding
- MessagingChatRelay: bidirectional agent session relay with output
  buffering to avoid message flooding
- ContentSanitizer: strips paths, env vars, code blocks from outbound
  messages to prevent leaking sensitive content
- MessagingService orchestrator: coordinates all components
- DI container registration with lazy proxy for zero-cost CLI startup
- CLI: shep settings messaging wizard (connect/status/disconnect)
- Daemon: start/stop messaging service in _serve command
- 39 unit tests covering all components

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…x spec yaml

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… scan

The content-sanitizer test used 'sk-abc123def456' as a dummy API key
value, which gitleaks flagged as a generic-api-key secret. Replaced
with 'test-value' which still exercises the env-var stripping logic
without triggering the secret scanner.
Replace the hand-rolled messaging scaffolding with a working end-to-end
integration against the Commands.com Gateway. Users can now pair a
Telegram bot via the web UI or CLI, point their bot webhook at the
gateway's public ingress URL, and drive Shep from their phone with
slash commands plus an interactive /chat relay that streams agent
output back over Telegram.

Core additions:
- IGatewayClient + HttpGatewayClient for OAuth token fetch and
  integration route registration
- Tunnel adapter rewritten with the ws library so bearer headers work
  on upgrade, speaking the real tunnel.activate/request/response protocol
- IMessageSender output port decouples outbound delivery from inbound
  tunnel frames; TelegramMessageSender implements it via HttpTelegramClient
- Webhook parsers for Telegram Update and WhatsApp Business Cloud payloads
- Begin/Confirm/Disconnect pairing use cases shared by CLI and Web
- Interactive /chat relay subscribes to IInteractiveSessionService and
  forwards deltas back to chat; free-form text during a relay goes to
  sendUserMessage
- Per-platform botToken in settings with env var fallback
- Web settings section, storybook stories, e2e test, and local setup docs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Refresh the allowlist entry for the fake api key in content-sanitizer
test to reference the rebased commit sha so gitleaks scans pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@arielshad arielshad force-pushed the feat/messaging-remote-control branch 2 times, most recently from 42b1f72 to d333ae0 Compare April 6, 2026 15:48
arielshad and others added 3 commits April 9, 2026 19:12
Feature 082 shipped with several silent gaps that prevented the Telegram
remote control flow from ever completing a real pairing. This change
closes all of them so /pair, /list, /help actually round-trip between
the user's chat and the Shep daemon.

- add migration 056 with 24 nullable messaging_* settings columns;
  safe defaults mean older builds keep working untouched
- extend sqlite settings mapper + repository to round-trip messagingconfig
- relax isconfigured so the tunnel starts in pending-pairing state and
  can auto-confirm /pair <code> over the wire
- fix tunnel.activate frame shape to send a batched routes array and
  parse the gateway's results array response (prior code sent the wrong
  singular shape so no routes were ever activated)
- gate messaging startup in dev-server.ts behind shep-enable-messaging
- add 4 round-trip persistence tests and update tunnel adapter tests;
  96 targeted tests pass

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Resolve merge conflicts from main (v1.181.0) including:
- DI container: keep both messaging service and application/terminal imports
- TypeSpec: include both messaging.tsp and application.tsp entity imports
- Generated output.ts: preserve messaging types alongside application types
- Interactive executor test: adopt main's V2 SDK systemPrompt behavior
- Add missing messaging translation key for Ukrainian locale

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
BeginMessagingPairingUseCase calls HttpGatewayClient which makes real
HTTP requests to a Commands.com Gateway that does not exist in the E2E
environment. The pairing server action silently fails, so the dialog
never opens and the test times out waiting for messaging-pairing-dialog.

Add StubGatewayClient that returns deterministic fake responses and
register it via SHEP_MOCK_GATEWAY=1 env var (same pattern as
SHEP_MOCK_EXECUTOR). Pass the env var in playwright.config.ts so the
dev server uses the stub during E2E runs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

Dev Release Published

Artifact Version Install
npm 1.181.0-pr512.ba01d33 npm install -g @shepai/cli@1.181.0-pr512.ba01d33

Published from commit 2529d68 | View CI

@github-actions
Copy link
Copy Markdown
Contributor

Dev Release Published

Artifact Version Install
npm 1.182.0-pr512.369be8e npm install -g @shepai/cli@1.182.0-pr512.369be8e

Published from commit 3ae33e6 | View CI

arielshad and others added 2 commits April 26, 2026 19:56
Co-Authored-By: Shep Bot <shep-agent@users.noreply.github.com>
Co-Authored-By: Shep Bot <shep-agent@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

Dev Release Published

Artifact Version Install
npm 1.193.0-pr512.745ede6 npm install -g @shepai/cli@1.193.0-pr512.745ede6

Published from commit e37c020 | View CI

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.

3 participants