feat(app): merge local and remote message sources#389
Open
ethfumi wants to merge 6 commits into
Open
Conversation
Add --after-id to the team messages endpoint so polling clients can fetch rows strictly after a cursor. Forward pages select the oldest matching rows before emitting them in ascending order, preventing gaps when more than the requested limit arrives between polls; backward history keeps its existing newest-page behavior. Reject simultaneous before/after cursors and cover both cursor exclusivity and multi-page forward ordering in the API tests.
Allow Team Room to combine the implicit local agmsg installation with read-only installations reached over SSH. Sources are configured in ~/.agmsg/config/app-sources.json and queried through the public api.sh interface with the system SSH client; the app never mounts, copies, or synchronizes messages.db and does not store credentials. Keep history pages and live cursors independent per source, deduplicate messages with source-qualified ids, and merge them in stable timestamp order. Modern remotes use lossless --after-id polling while older cores fall back to refreshing their latest 100 messages. Show source badges and remote members for filtering while keeping spawn, rename, leave, and compose operations local-only. Add source validation, Rust and frontend coverage, and configuration documentation.
Resolve the sidebar member list, where fujibee#385 (agent and team status) and multi-source support both rewrote the same block. Everything else merges cleanly. Take the pane status dot from fujibee#385 and drop the running dot it replaced. Keep the source-qualified key, since two sources can carry members with the same name. Keep the read-only guards for members that come from a remote source: no spawn, no context menu, source label in the title. Read-only members have no local pane, so their status is null and the check slot renders empty.
A read-only member from a remote source showed the status dot of a local pane when both carried the same name. Reproduce by joining claude-win on both a Windows and a Mac installation, then spawning the Windows one: the Mac claude-win shows a running dot although nothing runs on the Mac. Panes are local-only, and member names are unique per source rather than globally, so matching a pane on the name alone breaks as soon as two sources carry the same name. Exclude read-only members before the lookup. Both fujibee#385 and the multi-source work matched panes by name, so the gap predates this branch and only surfaced once the two met. The 91 frontend tests stayed green throughout; it took spawning an agent against a real two-source setup to see it.
e5b1fce to
cf7beca
Compare
The multi-source work reformatted the tests module's import list to add message_sources, shell_quote, and valid_source_id, and dropped run_script while doing so. The four tests that call it are gated on #[cfg(not(target_os = "windows"))], so on Windows they are compiled out and the missing import never surfaces — cargo test stays green. macOS compiles them and fails with E0425. Found by running the suite on a fork PR before proposing this upstream; the Windows-only local runs could not have caught it.
Resolve the app-user prompt in the initial team load, where fujibee#391 (persist UI settings) and multi-source support both changed the same condition. Everything else merges cleanly. Keep both conditions. fujibee#391 adds a suppression flag so a dismissed prompt stays dismissed across restarts; multi-source narrows the check to the local source, since the composer writes locally and a member carrying APP_USER_TYPE on a read-only remote cannot stand in for a local app user. Take fujibee#391's auto flag on the modal. Verified on Windows: frontend 92 passed, tsc clean, Rust 51 passed. The macOS and bats legs run on the fork before this goes back to the PR — a Windows-only run cannot see cfg(not(windows)) code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
agmsg の DB はインストールごとに独立していて、アプリは自分のマシンのものを見ます。エージェントを1台に集約している構成では、これで過不足ありません。
私は Mac と Windows の両方で開発していて、エージェントもマシンごとに分けています。エージェントは自分が動いているマシンのファイルを触るため、担当する作業がマシンに紐づくと、そのマシンで動かすことになるからです。
この構成に至る前に、DB を1台へ集約し、他方のマシンからは SSH で読みに行く方式を試しました。これは失敗でした。受信 hook はエージェントのターンの区切りごとに走るため、毎回 SSH の往復が入ります。通常は軽くても、相手のマシンが sleep していたり LAN が不安定だったりすると待ちが発生し、エージェントが固まって見えます。ターンの区切りという最も待たされたくない場所に、ネットワークが入っていました。
DB を rsync で同期する案も検討しましたが、SQLite の WAL・既読状態・同時書き込みの衝突を避けるため採用していません。
結果として、各マシンが自分の DB を持ち、メッセージは宛先のいるマシンの DB に書く形に落ち着きました。送受信の経路は完全にローカルで、エージェントのホットパスにネットワークはありません。
残ったのは閲覧だけです。会話は複数の DB に分かれて記録され、1枚の窓に両方は映りません。デスクトップアプリはターミナルと違い、ユーザーが1台の前に座って1つのウィンドウを見る道具なので、ここが効いてきます。ターミナルであれば、Mac の会話は Mac の shell で読めば済みます。
「no daemon, no network」との関係
この変更が README の原則に触れる可能性があることは認識しています。判断はお任せしたいのですが、私の理解では次のようになっています。
app-sources.jsonを書かなければ挙動は現在とまったく同じで、単一 DB のままです。ネットワークに触れるのはデスクトップアプリの表示経路だけ、という整理です。ただ、これで原則の範囲内と言えるのかは、私よりも判断できる立場ではないと思っています。
変更内容
Team Room が、暗黙のローカルインストールと、SSH 経由で読み取り専用として参照するインストールを、ひとつの表示に統合できるようになります。source は
~/.agmsg/config/app-sources.jsonで宣言し、公開インターフェースであるapi.shを、システムの SSH クライアント経由で呼びます。履歴のページングと live カーソルは source ごとに独立して持ちます。メッセージは source で修飾した id で重複排除し、timestamp の安定ソートでマージします。新しい remote は #388 で追加した取りこぼしのない
--after-idで polling し、それ以前の core を使っている remote は初回アクセス時に検出して、最新100件を取り直す方式へ fallback します。対象範囲
remote source は読み取り専用です。spawn・rename・leave・送信はローカル限定のままで、remote のメンバーは名簿とフィルタには現れますが、起動もメッセージ送信もできません。
既知の挙動
複数の source が同じ名前のメンバーを持つ場合、名簿には source ごとに1行ずつ並びます。フィルタは名前単位のため、両方の行のチェックは連動します。名寄せは行っていません。
これは主に、remote のインストールへ直接 join していたメンバーで起きます。その運用こそ本変更が不要にするものなので、必要性が出た時点で対応できればと思っていますが、ご意見あれば伺いたいです。
依存
#388 に依存します。そちらがマージされてからで構いません。
検証
おわりに
問題なさそうであれば、マージしていただけると嬉しいです。方針に合わないようであれば、遠慮なく閉じてください。fork で使い続けるので困りません。
需要が私だけのものなのか、他の方にもあるのかも分かっていません。そのあたりも含めてご判断いただければと思います。