Skip to content

feat: session sharing — cross-user conversation transfer via /share-session#327

Open
HuaweiREN wants to merge 16 commits into
xvirobotics:mainfrom
HuaweiREN:pr/session-sharing
Open

feat: session sharing — cross-user conversation transfer via /share-session#327
HuaweiREN wants to merge 16 commits into
xvirobotics:mainfrom
HuaweiREN:pr/session-sharing

Conversation

@HuaweiREN

Copy link
Copy Markdown

Summary

Adds /share-session @user and /claim <code> commands that allow users to transfer their Claude conversation session to other Feishu users, even under perUserContext isolation mode.

Depends on PR #324 (perUserContext).

Motivation

When perUserContext: true is enabled, each user has an isolated Claude session — great for privacy, but breaks collaborative workflows where context handoff is needed (e.g., developer shift change).

Design

  • /share-session @userB @userC — creates pending transfers with 6-char share codes, 30-min TTL
  • /share-session ou_xxxxxxxxxxxx — private chat fallback via raw open_id
  • Auto-Claim: recipient sends ANY message → session auto-links before normal processing
  • /claim <shareCode> — explicit manual claim
  • Three-layer storage alignment: SessionManager (JSON) + SessionRegistry (SQLite) + PersistentExecutor (process)

New Module: SessionSharing (src/bridge/session-sharing.ts)

In-memory dual-indexed store (by userId + shareCode) with periodic TTL cleanup.

Type Change: IncomingMessage.mentions

New optional field carrying raw @mention data. Event handler filters bot own @ before passing upstream.

Behavioral Semantics

Scenario Behavior
A shares → B auto-claims B sees A full chat history
B chats 10 turns → A messages A sees B additions (shared sessionId)
A /reset Only A scopeKey cleared; B unaffected
B /reset Only B scopeKey cleared; A unaffected

Backward Compatibility

  • No new dependencies
  • mentions field optional — Telegram/Web unaffected
  • All existing commands unchanged

Files Changed

  • src/bridge/session-sharing.ts (new)
  • src/bridge/command-handler.ts
  • src/bridge/message-bridge.ts
  • src/feishu/event-handler.ts
  • src/types.ts

5 files, +462 −2

floodsung and others added 16 commits May 15, 2026 01:46
* feat(installer): allow custom install directory via --dir / -Dir flag

install.sh and install.ps1 previously hardcoded the install path to
$HOME/metabot. Add a CLI flag (and matching PowerShell parameter) plus
an interactive prompt so users can install MetaBot anywhere.

- Priority: --dir / -Dir > METABOT_HOME env var > prompt > default.
- Tilde expansion + absolute-path validation; refuses to clobber
  $HOME / system roots.
- Persists METABOT_HOME to ~/.bashrc / ~/.zshrc (Linux/macOS) or
  user-level env (Windows) when non-default, so the mm/mb/metabot
  CLIs can locate the install in new shells.

* fix(codex): show model metadata in cards

* fix(codex): mirror skills and avoid bwrap sandbox

* fix(codex): tolerate agents deployment failures

* fix(codex): install bundled skills when user cache is empty

* docs: explain Codex skill migration

* feat(cluster): add federated identity foundation

---------

Co-authored-by: Flood Sung <floodsung@xvirobotics.ai>
* feat(installer): allow custom install directory via --dir / -Dir flag

install.sh and install.ps1 previously hardcoded the install path to
$HOME/metabot. Add a CLI flag (and matching PowerShell parameter) plus
an interactive prompt so users can install MetaBot anywhere.

- Priority: --dir / -Dir > METABOT_HOME env var > prompt > default.
- Tilde expansion + absolute-path validation; refuses to clobber
  $HOME / system roots.
- Persists METABOT_HOME to ~/.bashrc / ~/.zshrc (Linux/macOS) or
  user-level env (Windows) when non-default, so the mm/mb/metabot
  CLIs can locate the install in new shells.

* fix(codex): show model metadata in cards

* fix(codex): mirror skills and avoid bwrap sandbox

* fix(codex): tolerate agents deployment failures

* fix(codex): install bundled skills when user cache is empty

* docs: explain Codex skill migration

* feat(memory): add namespace scoped instance token

---------

Co-authored-by: Flood Sung <floodsung@xvirobotics.ai>
* feat(installer): allow custom install directory via --dir / -Dir flag

install.sh and install.ps1 previously hardcoded the install path to
$HOME/metabot. Add a CLI flag (and matching PowerShell parameter) plus
an interactive prompt so users can install MetaBot anywhere.

- Priority: --dir / -Dir > METABOT_HOME env var > prompt > default.
- Tilde expansion + absolute-path validation; refuses to clobber
  $HOME / system roots.
- Persists METABOT_HOME to ~/.bashrc / ~/.zshrc (Linux/macOS) or
  user-level env (Windows) when non-default, so the mm/mb/metabot
  CLIs can locate the install in new shells.

* fix(codex): show model metadata in cards

* fix(codex): mirror skills and avoid bwrap sandbox

* fix(codex): tolerate agents deployment failures

* fix(codex): install bundled skills when user cache is empty

* docs: explain Codex skill migration

* feat(skills): track owner metadata and hashes

---------

Co-authored-by: Flood Sung <floodsung@xvirobotics.ai>
* feat(installer): allow custom install directory via --dir / -Dir flag

install.sh and install.ps1 previously hardcoded the install path to
$HOME/metabot. Add a CLI flag (and matching PowerShell parameter) plus
an interactive prompt so users can install MetaBot anywhere.

- Priority: --dir / -Dir > METABOT_HOME env var > prompt > default.
- Tilde expansion + absolute-path validation; refuses to clobber
  $HOME / system roots.
- Persists METABOT_HOME to ~/.bashrc / ~/.zshrc (Linux/macOS) or
  user-level env (Windows) when non-default, so the mm/mb/metabot
  CLIs can locate the install in new shells.

* fix(codex): show model metadata in cards

* fix(codex): mirror skills and avoid bwrap sandbox

* fix(codex): tolerate agents deployment failures

* fix(codex): install bundled skills when user cache is empty

* docs: explain Codex skill migration

* feat(cluster): bootstrap peers from cluster url

---------

Co-authored-by: Flood Sung <floodsung@xvirobotics.ai>
* feat(installer): allow custom install directory via --dir / -Dir flag

install.sh and install.ps1 previously hardcoded the install path to
$HOME/metabot. Add a CLI flag (and matching PowerShell parameter) plus
an interactive prompt so users can install MetaBot anywhere.

- Priority: --dir / -Dir > METABOT_HOME env var > prompt > default.
- Tilde expansion + absolute-path validation; refuses to clobber
  $HOME / system roots.
- Persists METABOT_HOME to ~/.bashrc / ~/.zshrc (Linux/macOS) or
  user-level env (Windows) when non-default, so the mm/mb/metabot
  CLIs can locate the install in new shells.

* fix(codex): show model metadata in cards

* fix(codex): mirror skills and avoid bwrap sandbox

* fix(codex): tolerate agents deployment failures

* fix(codex): install bundled skills when user cache is empty

* docs: explain Codex skill migration

* docs: document federated memory and skill hub

---------

Co-authored-by: Flood Sung <floodsung@xvirobotics.ai>
* feat(installer): allow custom install directory via --dir / -Dir flag

install.sh and install.ps1 previously hardcoded the install path to
$HOME/metabot. Add a CLI flag (and matching PowerShell parameter) plus
an interactive prompt so users can install MetaBot anywhere.

- Priority: --dir / -Dir > METABOT_HOME env var > prompt > default.
- Tilde expansion + absolute-path validation; refuses to clobber
  $HOME / system roots.
- Persists METABOT_HOME to ~/.bashrc / ~/.zshrc (Linux/macOS) or
  user-level env (Windows) when non-default, so the mm/mb/metabot
  CLIs can locate the install in new shells.

* fix(codex): show model metadata in cards

* fix(codex): mirror skills and avoid bwrap sandbox

* fix(codex): tolerate agents deployment failures

* fix(codex): install bundled skills when user cache is empty

* docs: explain Codex skill migration

* fix(cli): use instance memory token

---------

Co-authored-by: Flood Sung <floodsung@xvirobotics.ai>
* feat(installer): allow custom install directory via --dir / -Dir flag

install.sh and install.ps1 previously hardcoded the install path to
$HOME/metabot. Add a CLI flag (and matching PowerShell parameter) plus
an interactive prompt so users can install MetaBot anywhere.

- Priority: --dir / -Dir > METABOT_HOME env var > prompt > default.
- Tilde expansion + absolute-path validation; refuses to clobber
  $HOME / system roots.
- Persists METABOT_HOME to ~/.bashrc / ~/.zshrc (Linux/macOS) or
  user-level env (Windows) when non-default, so the mm/mb/metabot
  CLIs can locate the install in new shells.

* fix(codex): show model metadata in cards

* fix(codex): mirror skills and avoid bwrap sandbox

* fix(codex): tolerate agents deployment failures

* fix(codex): install bundled skills when user cache is empty

* docs: explain Codex skill migration

* Cache peer Skill Hub artifacts

---------

Co-authored-by: Flood Sung <floodsung@xvirobotics.ai>
Co-authored-by: Flood Sung <floodsung@xvirobotics.ai>
* Mirror peer MetaMemory documents

* Add stable bot memory namespaces

---------

Co-authored-by: Flood Sung <floodsung@xvirobotics.ai>
* Mirror peer MetaMemory documents

* Add stable bot memory namespaces

* Update lark CLI via metabot update

---------

Co-authored-by: Flood Sung <floodsung@xvirobotics.ai>
When a bot opts in via `perUserContext: true`, conversation state
(session, persistent executor, message queue, running task) is keyed
by `chatId:userId` instead of `chatId`. This gives each Feishu member
in a group chat their own Claude thread.

Changes:
- composeScopeKey / chatIdFromScopeKey / userIdFromScopeKey helpers
- SessionManager, ExecutorRegistry: opaque scopeKey parameter
- MessageBridge: thread scopeKey through all conversation-state Maps
- CommandHandler: /reset, /stop, /status, /model scoped by caller
- ExecutorRoutes: adjusted for scopeKey
- Config: perUserContext bot flag wired through JSON loader
- Tests: compose-key (8 tests) + per-user-context (12 tests)
- Bump default executor pool cap 20 -> 50 for per-user multiplier

Back-compat: default false/undefined preserves byte-for-byte identical
behavior. Existing session JSON files load unchanged.
- Add perUserContext to CLAUDE.md Configuration section
- Add perUserContext example to bots.example.json
- Enable perUserContext: true for Baymax in bots.json
Thread msg.userId through ApiContext so the Claude executor (and the
persistent variant) can mention "The current user's ID is <open_id>" in
the system prompt appendix. Groundwork for per-user context keying — the
userId is now reliably available on the wire end-to-end.
Implements plan C for cross-user session transfer:

- /share-session @user — creates a pending 30-min transfer,
  generates a share code. Target user can auto-claim by sending
  any message to the bot, or use /claim <code> explicitly.

- /claim <code> — explicitly claim a shared session by code.

- mentions now flow through IncomingMessage so @mention
  resolution works in command handlers.

- SessionSharing (new): in-memory store for pending transfers,
  keyed by userId and shareCode, with TTL cleanup.

- Bridge auto-checks pending transfers on every incoming
  non-command message — if found, links the target scopeKey
  to the source Claude sessionId before processing.

- Also supports /share-session <open_id> for private chats
  where @mentions are unavailable.
When the user types '@bot /share-session @targetUser', the
mentions array includes both the bot and the target. Previously
mentions[0] was used which picked up the bot itself. Now the
event handler filters out botOpenId before passing mentions
through to IncomingMessage.
Previously only mentions[0] was used. Now iterates over all
mentions (after bot filtering) and creates a transfer for each.
Also added 'i' parameter to map that's unused — removed.
Success message now lists all recipients with their codes.
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.

2 participants