murmur-it 0.0.0-stage → 0.2.1-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +55 -0
- package/LICENSE +21 -0
- package/README.md +125 -2
- package/adapters/hummin/murmur.ts +467 -0
- package/adapters/opencode/murmur.ts +304 -0
- package/bin/murmur.js +11 -0
- package/dist/broker.js +1050 -0
- package/dist/cli.js +588 -0
- package/dist/client.js +210 -0
- package/dist/config.js +83 -0
- package/dist/core.js +779 -0
- package/dist/hooks.js +120 -0
- package/dist/install.js +250 -0
- package/dist/mcp.js +217 -0
- package/dist/native.js +125 -0
- package/dist/proc.js +110 -0
- package/dist/proof.js +111 -0
- package/dist/protocol.js +92 -0
- package/dist/store.js +496 -0
- package/dist/wake.js +12 -0
- package/package.json +63 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to murmur are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
|
|
5
|
+
[Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [0.2.1-rc.1] - 2026-10-20
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- Release pipeline check: the first version published to npm by CI through trusted publishing, as a prerelease on the `next` dist-tag. No code changes.
|
|
12
|
+
|
|
13
|
+
## [0.2.0] - 2026-10-20
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- CLI-agnostic hooks: one hook entry (`murmur hook <event> --client <cli>`) for Claude Code, Codex, Gemini CLI and zcode, each speaking that CLI's hook dialect.
|
|
18
|
+
- `murmur install <claude|codex|gemini|zcode|opencode|hummin>`: idempotent merges into each CLI's own config, with a one-time `.bak-murmur` backup of every touched file.
|
|
19
|
+
- opencode plugin (`adapters/opencode/murmur.ts`): tools, push with `promptAsync`, presence.
|
|
20
|
+
- Hummin extension (`adapters/hummin/murmur.ts`): tools, push with `sendUserMessage`, and a model-free `/murmur`.
|
|
21
|
+
- Host-process identity (`src/proc.ts`): a session is identified by its host process, so one global config serves every session and no per-session handle is configured. Sessions are named `<cli>-<folder>` with a numeric suffix for more live sessions in the same folder; restarts reuse their old name.
|
|
22
|
+
- `murmur name <handle>` and the `murmur_name` tool rename a session while keeping its messages, deliveries and groups.
|
|
23
|
+
- `murmur send --as <handle>` and `murmur reply --as <handle>` for scripted agents. Commands run from an agent's shell speak as that agent; from a plain terminal they speak as the owner.
|
|
24
|
+
- `murmur slash`: the `/murmur` backing, with a quoted-heredoc form so quotes, `$(...)`, backticks and `;` arrive verbatim, `--claude-escaped` for Claude Code's `!` escaping, and bare discovery output (usage, peers, groups).
|
|
25
|
+
- Delivery proof (`src/proof.ts`): `delivered` now requires evidence from the receiving side (the message tag in the receiver's own transcript, an adapter confirmation, or a hook handover). `sent` is never reported as `delivered`.
|
|
26
|
+
- Notes to senders: `queued_delivered` when a queued message finally arrives, `peer_offline` when a session ends with unconsumed messages.
|
|
27
|
+
- `murmur_ack` to tell senders a message was seen and will be answered later.
|
|
28
|
+
- Live checks against real CLIs in tmux (`scripts/live/`, `make verify CLI=<cli>`) and a benchmark (`scripts/bench.mjs`).
|
|
29
|
+
- Packaging for npm, a CI workflow, a release workflow with npm trusted publishing, and a documentation site.
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
|
|
33
|
+
- Claude Code native transport corrected from the Claude binary's own injection recipe: `{"type":"auth",...}` then `{"type":"user","message":{...}}`. v0.1 guessed a different frame and counted a clean socket close as delivered.
|
|
34
|
+
- Performance: SQLite indexes, a prepared statement cache, a lazily imported MCP SDK (only `murmur mcp` loads it), and a single per-pid `ps` walk for identity.
|
|
35
|
+
- Wire protocol version 2.
|
|
36
|
+
|
|
37
|
+
### Removed
|
|
38
|
+
|
|
39
|
+
- `scripts/e2e.mjs`, replaced by the live checks in `scripts/live/`.
|
|
40
|
+
|
|
41
|
+
## [0.1.0] - 2026-10-20
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
|
|
45
|
+
- Local session message bus: one broker process owning a SQLite store and one Unix domain socket, with token authentication.
|
|
46
|
+
- Group threads: one message fans out to any mix of handles and groups; replies reach the whole thread; per-thread monotonic `seq`.
|
|
47
|
+
- Delivery states per recipient (queued, sent, delivered, acknowledged, replied) and verdicts (`agree`, `disagree`, `info`).
|
|
48
|
+
- Presence (busy, idle, online, presumed-offline, offline) and `murmur_wait` with per-peer reply latency p50 and p95.
|
|
49
|
+
- Native Claude Code socket transport, an MCP server exposing the bus as tools, a CLI, and an installer.
|
|
50
|
+
- Limits: send rate, duplicate window, thread and inbox caps.
|
|
51
|
+
- 283 tests at 100 percent lines and branches, and an end-to-end rig that replayed the live 3-peer scenario.
|
|
52
|
+
|
|
53
|
+
[0.2.1-rc.1]: https://github.com/rennf93/murmur/releases/tag/v0.2.1-rc.1
|
|
54
|
+
[0.2.0]: https://github.com/rennf93/murmur/releases/tag/v0.2.0
|
|
55
|
+
[0.1.0]: https://github.com/rennf93/murmur/releases/tag/v0.1.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Renn F
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,126 @@
|
|
|
1
|
-
#
|
|
1
|
+
# murmur
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Murmur is a local message bus for AI CLI sessions that share one machine and one user account. One broker process owns a SQLite store and one Unix domain socket; every agent session joins as a named peer, and peers talk in threads. One send produces one message that fans out to any mix of handles and groups, so no session writes the same announcement twice and no session relays another's words by hand. A reply reaches everyone in the thread. Senders always see, per recipient, whether a message is still queued, was handed to the session, was proven to have reached it, or was answered.
|
|
4
|
+
|
|
5
|
+
It works with Claude Code, Codex, Gemini CLI, zcode, opencode and Hummin. Each joins through the deepest hook its CLI offers (see the truth table), and any process that can run a shell command can use the `murmur` CLI.
|
|
6
|
+
|
|
7
|
+
Full documentation: https://rennf93.github.io/murmur/ (concepts, per-CLI pages, command, MCP and protocol reference, releasing). See also [CHANGELOG.md](CHANGELOG.md), [CONTRIBUTING.md](CONTRIBUTING.md) and [SECURITY.md](SECURITY.md).
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
Requires Node 20 or newer.
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
npm install -g murmur-it # the package is murmur-it; the command it installs is murmur
|
|
15
|
+
murmur init # ~/.murmur (0700), token (0600), murmur.db, owner peer
|
|
16
|
+
murmur install claude # and/or: codex | gemini | zcode | opencode | hummin
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
From source instead: `npm install && npm run build && npm link` in a clone (puts the same `murmur` on PATH; every hook, MCP entry and command runs plain `murmur`).
|
|
20
|
+
|
|
21
|
+
The broker starts on demand: the first hook, MCP server or CLI command that finds it down starts one in the background (`murmur serve` runs it in the foreground; `murmur serve --daemon` detaches). `MURMUR_HOME` relocates the home for every component.
|
|
22
|
+
|
|
23
|
+
What each installer writes (idempotent merges; every touched file gets a one-time `.bak-murmur` copy first):
|
|
24
|
+
|
|
25
|
+
| CLI | Files | Notes |
|
|
26
|
+
| --- | --- | --- |
|
|
27
|
+
| claude | `~/.claude/settings.json` hooks (SessionStart, UserPromptSubmit, Stop, SessionEnd), `mcpServers.murmur` in `~/.claude.json`, `~/.claude/commands/murmur.md` | Removes the old `CHANGE-ME-per-session` handle placeholder. |
|
|
28
|
+
| codex | `~/.codex/hooks.json` (SessionStart, UserPromptSubmit, Stop, SessionEnd), `[mcp_servers.murmur]` in `~/.codex/config.toml`, `~/.codex/prompts/murmur.md` | Codex asks you to trust new hooks once: open `/hooks`. The command is `/prompts:murmur`. |
|
|
29
|
+
| gemini | `~/.gemini/settings.json` hooks (SessionStart, BeforeAgent, AfterAgent, SessionEnd) and `mcpServers.murmur`, `~/.gemini/commands/murmur.toml` | |
|
|
30
|
+
| `zcode` | Hooks fire under workspace trust; the session announces; one message is handed over by a hook and answered | BLOCKED: the provider answers 429 "Insufficient balance or no resource package. Please recharge." and the session never announced in headless mode, so whether hooks fire under `-p` is unverified |
|
|
31
|
+
| opencode | `~/.config/opencode/plugins/murmur.ts`, `~/.config/opencode/commands/murmur.md` | The plugin is the whole integration (tools, push, presence). |
|
|
32
|
+
| hummin | `~/.hummin/agent/extensions/murmur.ts` | The extension is the whole integration, including a model-free `/murmur`. |
|
|
33
|
+
|
|
34
|
+
## Identity: no per-session config
|
|
35
|
+
|
|
36
|
+
Every hook, MCP server and CLI command walks up its process ancestors and takes the first one that is not a shell. That process is the session's host (claude, codex, zcode's node, gemini's node). A hook and an MCP server of the same session find the same host, so one global config serves every session. The opencode plugin and the Hummin extension run inside the host and announce themselves directly.
|
|
37
|
+
|
|
38
|
+
- A new session is named `<cli>-<folder>` (`claude-murmur`, `codex-guard-core`), then `-2`, `-3` for more live sessions in that folder. A name whose sessions have all ended is reused, so a restarted session in the same folder rejoins its groups and inbox.
|
|
39
|
+
- Rename with the `murmur_name` tool, or `murmur name <handle>` from the session's shell. A rename keeps every message, delivery and group membership. Taking a name held by another live session is refused; taking one held by an ended session joins that identity.
|
|
40
|
+
- Resume (same CLI session id, new process) and clear (new id, same process) keep the name.
|
|
41
|
+
- `murmur send` and `murmur reply` run from an agent's shell speak as that agent's session; run from a plain terminal they speak as the owner. `--as <handle>` overrides. `/murmur` always speaks as the owner, because it is you typing.
|
|
42
|
+
|
|
43
|
+
## Delivery truth table
|
|
44
|
+
|
|
45
|
+
Delivery states, per recipient: `queued` (stored, nothing left the broker), `sent` (a transport accepted it), `delivered` (evidence from the receiving side), `acknowledged` (`murmur_ack`: seen, answer later), `replied`. `sent` is never reported as `delivered`.
|
|
46
|
+
|
|
47
|
+
| CLI | Live push into a running session | Waiting messages also arrive | Evidence for `delivered` |
|
|
48
|
+
| --- | --- | --- | --- |
|
|
49
|
+
| Claude Code | Native messaging socket (`CLAUDE_CODE_MESSAGING_SOCKET`): the session gets the message as a peer turn; an idle session starts working on it | At SessionStart, each prompt, and at turn end (Stop continues the turn) | The message tag found in the receiver's own transcript |
|
|
50
|
+
| Hummin | Extension calls `sendUserMessage` (follow-up when idle, steer mid-turn) | When the extension (re)connects | The extension confirms its session accepted it; the tag in the session file too |
|
|
51
|
+
| opencode | Plugin posts the message into the session with `promptAsync` | When the plugin (re)connects | The plugin confirms the post succeeded |
|
|
52
|
+
| Codex | `codex queue --thread <id>`; a running window takes it as a user turn | At SessionStart, each prompt, and at turn end (Stop continues the turn) | The tag in the receiver's rollout transcript |
|
|
53
|
+
| Gemini CLI | None: Gemini has no inbound channel | At SessionStart, each prompt (BeforeAgent), and at turn end (AfterAgent continues the turn) | Handed over by the hook |
|
|
54
|
+
| `zcode` | Hooks fire under workspace trust; the session announces; one message is handed over by a hook and answered | BLOCKED: the provider answers 429 "Insufficient balance or no resource package. Please recharge." and the session never announced in headless mode, so whether hooks fire under `-p` is unverified |
|
|
55
|
+
|
|
56
|
+
Delivery modes: `push` (default) uses every path above; `notify` stores the message and sends a small batched note; `silent` only stores. A message for a session that is down stays `queued`; when that session comes back its queued messages are pushed (or handed over at its next hook) and the sender gets a `queued_delivered` note. A session that ends with messages still unconsumed triggers a `peer_offline` note to their senders.
|
|
57
|
+
|
|
58
|
+
What a session sees for every message, on every path:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
[murmur m42 t7 s0 from ledger-3 to archify-2, prs-5]
|
|
62
|
+
<body, cut at 4000 characters with a pointer to the full text>
|
|
63
|
+
(reply: murmur_reply messageId 42, or from a shell: murmur reply 42 <text>; whole thread: murmur_thread 7)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Threads, groups, verdicts
|
|
67
|
+
|
|
68
|
+
- One message, one id, fanned out. Targets are handles and groups: `@name` is always a group; a bare name is a handle, or the group of that name when no peer has that handle. Overlapping groups dedupe.
|
|
69
|
+
- Replies go to everyone in the thread (every sender and recipient so far), in the parent's mode, so peers see each other's answers without relaying.
|
|
70
|
+
- Every message has a per-thread monotonic `seq`. `murmur_thread` returns first lines by default, full bodies with `full`, and only newer messages with `sinceSeq`.
|
|
71
|
+
- Verdicts: `agree`, `disagree`, `info`, with the body starting `AGREE`, `DISAGREE` or `INFO`. `murmur_wait` returns, for the thread's latest ask, each recipient's state, verdict and reply latency plus their historical p50 and p95, either when everyone (or anyone) replied or at the timeout (`timeoutMs: 0` returns now).
|
|
72
|
+
- `references` carries pointers (paths, commits, URLs) so artifacts stay in their repos.
|
|
73
|
+
- Groups: create, list, add, remove, delete. Deleting a group never touches sessions, threads or history.
|
|
74
|
+
|
|
75
|
+
## Tools and commands
|
|
76
|
+
|
|
77
|
+
MCP tools (Claude, Codex, Gemini, zcode): `murmur_send`, `murmur_reply`, `murmur_ack`, `murmur_thread`, `murmur_wait`, `murmur_groups`, `murmur_status`, `murmur_name`. The opencode plugin and the Hummin extension register the same tools minus `murmur_ack`.
|
|
78
|
+
|
|
79
|
+
The human surface, as the owner:
|
|
80
|
+
|
|
81
|
+
- `/murmur <group | @group | handle[,more]> <message>`; bare `/murmur` lists peers and groups. In Claude Code and zcode the command file runs `murmur slash --stdin` with the message in a quoted heredoc, so quotes, `$(...)`, backticks and `;` arrive verbatim (Claude Code turns a word-initial `!` into `\!` before the shell sees it; `--claude-escaped` turns it back); the model only shows the output. Hummin's `/murmur` runs with no model turn at all.
|
|
82
|
+
- `murmur send <targets> <body...> [--mode push|notify|silent] [--refs a,b] [--thread <id>] [--as <handle>]`
|
|
83
|
+
- `murmur reply <id> <body...> [--verdict agree|disagree|info] [--refs a,b] [--as <handle>]`
|
|
84
|
+
- `murmur status`, `murmur thread <id> [--since <seq>] [--full]`, `murmur groups [list|create|add|remove|delete] ...`, `murmur name <handle>`
|
|
85
|
+
|
|
86
|
+
## Doctrine
|
|
87
|
+
|
|
88
|
+
The bus removes two costs and must never remove a third thing. The costs: duplicated composition, where every member of a group reformats the same fact, and sender-side relaying, where one session carries another's words to a third and garbles them. One message fans out; replies reach the whole thread; the broker owns storage and delivery. Delivery modes are the token dial. The third thing is independent verification: a message is a claim, not evidence. Peers verify against the artifacts themselves, which is why messages carry `references`, and why every session is told so by the MCP server's instructions.
|
|
89
|
+
|
|
90
|
+
## Limits
|
|
91
|
+
|
|
92
|
+
- 20 sends per sender per 60 seconds; an identical send (sender, body, recipients) within 60 seconds is rejected as a duplicate. Replies count. In memory; reset on broker restart.
|
|
93
|
+
- 500 messages per thread; 200 unread deliveries per recipient; 1 MiB per request line.
|
|
94
|
+
- `murmur_wait`: default 120 s, at most 300 s.
|
|
95
|
+
- Hooks: 10 s hard deadline, up to 10 messages per pull, exit 0 on every failure path.
|
|
96
|
+
- Transcript proof polls for 120 s after a push, then re-checks at that session's next hook event.
|
|
97
|
+
- Notifications are batched per recipient over 60 seconds and are best effort.
|
|
98
|
+
|
|
99
|
+
## Security
|
|
100
|
+
|
|
101
|
+
- Unix domain socket only, mode 0600; no TCP. The home is 0700; the token file, the database and its WAL files are 0600.
|
|
102
|
+
- The first line on any connection must be `auth` with the token. That is the whole trust boundary: same OS user, by design.
|
|
103
|
+
- Messages are context a session reads, never permission decisions. Claude Code labels natively pushed messages as coming from another session, not from the user.
|
|
104
|
+
- The database stores each Claude session's messaging token (to push into it); it lives only under the 0600 database.
|
|
105
|
+
|
|
106
|
+
## Verification
|
|
107
|
+
|
|
108
|
+
- `make test`; `make coverage` enforces 100 percent statements, branches, functions and lines.
|
|
109
|
+
- `node scripts/bench.mjs dist` prints p50 and p95 for a hook run, a CLI send, a 10-way fan-out, status over 50 sessions and a pull over 100k historical deliveries, plus burst throughput. On 2026-10-20 (Apple M2 Pro): hook 52 ms, send 74 ms, fan-out 0.33 ms, status 22 ms, pull 0.04 ms, 6900 sends/s.
|
|
110
|
+
- `make verify CLI=<cli>` (claude, codex, gemini, hummin, opencode or zcode; or `node scripts/live/<cli>.mjs [model]`) runs one live check against the real CLI in tmux: an isolated broker, the exact files `murmur install` writes (loaded as project config, so your real CLI config is only read for auth), one owner message, and a PASS or FAIL per step judged from the broker's own records. It spends a few cents of model calls.
|
|
111
|
+
|
|
112
|
+
| Check | What it proves | Last result (2026-10-20) |
|
|
113
|
+
| --- | --- | --- |
|
|
114
|
+
| `claude` | Two sessions announce with native transports; one message to both goes sent, delivered (tag in each transcript), replied; each reply fans out to the other session and the owner; `/murmur` stores `$(...)`, backticks, quotes, `!` and `$HOME` verbatim | PASS, haiku, replies in about 3.6 s |
|
|
115
|
+
| `codex` | The session announces with its thread id; `codex queue` reaches the running window; transcript proof; reply through the MCP tool | PASS, gpt-5.6-luna, 6.2 s |
|
|
116
|
+
| `hummin` | The extension injects, acks delivered, carries the reply; the model-free `/murmur` | PASS, zai/glm-5.3-flash, 6.0 s |
|
|
117
|
+
| `opencode` | The plugin announces, injects with `promptAsync`, acks delivered, carries the reply | PASS, opencode 1.19.3, opencode/glm-5.3-flash-free, reply in 5.2 s (the readiness check can take up to 60 s on the first start after an upgrade) |
|
|
118
|
+
| `gemini` | SessionStart announces; the message waits queued; BeforeAgent hands it over; reply through the MCP tool | Skipped by the owner on 2026-10-20: needs `GEMINI_API_KEY` (Gemini CLI 0.58 refuses the legacy personal login) |
|
|
119
|
+
| `zcode` | Hooks fire under workspace trust; the session announces; one message is handed over by a hook and answered | BLOCKED: the provider answers 429 "Insufficient balance or no resource package. Please recharge." and the session never announced in headless mode, so whether hooks fire under `-p` is unverified |
|
|
120
|
+
|
|
121
|
+
## Troubleshooting
|
|
122
|
+
|
|
123
|
+
- `murmur broker is down; start it with: murmur serve`: autostart failed (for example `murmur` is not on PATH for that process). Run `murmur serve --daemon`.
|
|
124
|
+
- A leftover `bus.sock` from a killed broker is removed on the next start; a second broker refuses to start while one is answering.
|
|
125
|
+
- `murmur status` shows who is on the bus, their CLI, and presence: `busy`/`idle` from the last lifecycle event of a running session, `online` for a running session or live connection with no event yet, then `presumed-offline` (seen in the last 5 minutes) or `offline`.
|
|
126
|
+
- Install refuses to touch a config file that is not valid JSON; fix or remove it first.
|
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* murmur: join a hummin session to the murmur local message bus.
|
|
3
|
+
*
|
|
4
|
+
* murmur (https://github.com/rennf93/murmur) is a client-agnostic bus for AI
|
|
5
|
+
* CLI sessions: group threads, delivery states, verdicts, presence. This is
|
|
6
|
+
* the hummin client, shaped like hummin-tg-hub (one long-lived broker socket
|
|
7
|
+
* per session, reconnect, model tools), speaking murmur wire protocol v2
|
|
8
|
+
* (newline-delimited JSON over $MURMUR_HOME/bus.sock):
|
|
9
|
+
*
|
|
10
|
+
* session_start -> auth + session-start announce -> {handle}
|
|
11
|
+
* agent_start/end -> prompt / stop lifecycle events (busy / idle)
|
|
12
|
+
* push event -> sendUserMessage(payload.text verbatim, steer when
|
|
13
|
+
* busy, followUp when idle) then a `delivered` frame
|
|
14
|
+
* notification evt -> one "[murmur notice]" line, only when idle
|
|
15
|
+
* murmur_* tools -> one request each on the same connection
|
|
16
|
+
* /murmur -> model-free: short cli connection that sends, or
|
|
17
|
+
* (bare) shows peers and groups
|
|
18
|
+
* session_shutdown -> session-end + close
|
|
19
|
+
*
|
|
20
|
+
* Config: MURMUR_HOME (default ~/.murmur) holds bus.sock and token.
|
|
21
|
+
* Murmur failures never throw into the session; the connection retries
|
|
22
|
+
* every 5 seconds while the session lives.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { execFileSync } from "node:child_process";
|
|
26
|
+
import { readFileSync } from "node:fs";
|
|
27
|
+
import { connect, type Socket } from "node:net";
|
|
28
|
+
import { homedir } from "node:os";
|
|
29
|
+
import { join } from "node:path";
|
|
30
|
+
import { Type } from "typebox";
|
|
31
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
32
|
+
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// config
|
|
35
|
+
|
|
36
|
+
const HOME = process.env.MURMUR_HOME ?? join(homedir(), ".murmur");
|
|
37
|
+
const SOCKET = join(HOME, "bus.sock");
|
|
38
|
+
const TOKEN_FILE = join(HOME, "token");
|
|
39
|
+
const PROTOCOL = 2;
|
|
40
|
+
const RECONNECT_MS = 5000;
|
|
41
|
+
const REQUEST_TIMEOUT_MS = 30_000;
|
|
42
|
+
|
|
43
|
+
type Json = Record<string, unknown>;
|
|
44
|
+
interface Host { hostPid: number; hostStart: string }
|
|
45
|
+
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
// socket client (request/reply by id, events to a callback)
|
|
48
|
+
|
|
49
|
+
interface Client {
|
|
50
|
+
request(body: Json, timeoutMs?: number): Promise<unknown>;
|
|
51
|
+
close(): void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function openClient(onEvent: (f: Json) => void, onClose: () => void): Promise<Client> {
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
let buf = "";
|
|
57
|
+
let nextId = 1;
|
|
58
|
+
let up = false;
|
|
59
|
+
const pending = new Map<number, { ok: (r: unknown) => void; fail: (e: Error) => void }>();
|
|
60
|
+
const sock: Socket = connect(SOCKET);
|
|
61
|
+
|
|
62
|
+
function failAll(e: Error): void {
|
|
63
|
+
for (const p of pending.values()) p.fail(e);
|
|
64
|
+
pending.clear();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const client: Client = {
|
|
68
|
+
request(body, timeoutMs = REQUEST_TIMEOUT_MS) {
|
|
69
|
+
return new Promise((ok, fail) => {
|
|
70
|
+
const id = nextId++;
|
|
71
|
+
const timer = setTimeout(() => {
|
|
72
|
+
pending.delete(id);
|
|
73
|
+
fail(new Error("murmur request timed out"));
|
|
74
|
+
}, timeoutMs);
|
|
75
|
+
pending.set(id, {
|
|
76
|
+
ok: (r) => (clearTimeout(timer), ok(r)),
|
|
77
|
+
fail: (e) => (clearTimeout(timer), fail(e)),
|
|
78
|
+
});
|
|
79
|
+
sock.write(JSON.stringify({ v: PROTOCOL, id, ...body }) + "\n", (err) => {
|
|
80
|
+
if (err && pending.delete(id)) (clearTimeout(timer), fail(err));
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
close() {
|
|
85
|
+
sock.end();
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
sock.on("data", (b) => {
|
|
90
|
+
buf += b.toString();
|
|
91
|
+
let nl: number;
|
|
92
|
+
while ((nl = buf.indexOf("\n")) >= 0) {
|
|
93
|
+
const line = buf.slice(0, nl);
|
|
94
|
+
buf = buf.slice(nl + 1);
|
|
95
|
+
let f: Json;
|
|
96
|
+
try {
|
|
97
|
+
f = JSON.parse(line) as Json;
|
|
98
|
+
} catch {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (f.type === "event") {
|
|
102
|
+
try {
|
|
103
|
+
onEvent(f);
|
|
104
|
+
} catch {
|
|
105
|
+
// a bad event must not kill the reader
|
|
106
|
+
}
|
|
107
|
+
} else if (typeof f.id === "number") {
|
|
108
|
+
const p = pending.get(f.id);
|
|
109
|
+
if (!p) continue;
|
|
110
|
+
pending.delete(f.id);
|
|
111
|
+
if (f.ok === true) p.ok(f.result);
|
|
112
|
+
else {
|
|
113
|
+
const err = f.error as { code?: string; message?: string } | undefined;
|
|
114
|
+
p.fail(new Error(`${err?.code ?? "error"}: ${err?.message ?? "murmur request failed"}`));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
sock.on("error", (e) => {
|
|
120
|
+
if (!up) reject(e);
|
|
121
|
+
failAll(e);
|
|
122
|
+
});
|
|
123
|
+
sock.on("close", () => {
|
|
124
|
+
failAll(new Error("murmur connection closed"));
|
|
125
|
+
if (up) onClose();
|
|
126
|
+
});
|
|
127
|
+
sock.on("connect", () => {
|
|
128
|
+
client
|
|
129
|
+
.request({ type: "auth", token: readFileSync(TOKEN_FILE, "utf8").trim() })
|
|
130
|
+
.then(() => {
|
|
131
|
+
up = true;
|
|
132
|
+
resolve(client);
|
|
133
|
+
})
|
|
134
|
+
.catch((e) => {
|
|
135
|
+
sock.destroy();
|
|
136
|
+
reject(e);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function readHost(): Host {
|
|
143
|
+
// hostStart must match what the broker computes: ps lstart under LC_ALL=C
|
|
144
|
+
let hostStart = "";
|
|
145
|
+
try {
|
|
146
|
+
hostStart = execFileSync("ps", ["-o", "lstart=", "-p", String(process.pid)], {
|
|
147
|
+
env: { ...process.env, LC_ALL: "C" },
|
|
148
|
+
encoding: "utf8",
|
|
149
|
+
}).trim();
|
|
150
|
+
} catch {
|
|
151
|
+
// broker will treat the host as unverifiable
|
|
152
|
+
}
|
|
153
|
+
return { hostPid: process.pid, hostStart };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function text(s: string, isError = false): { content: { type: "text"; text: string }[]; details: undefined; isError?: boolean } {
|
|
157
|
+
return { content: [{ type: "text", text: s }], details: undefined, ...(isError ? { isError } : {}) };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function fmtDeliveries(r: Json): string {
|
|
161
|
+
const lines = ((r.deliveries as { recipient: string; state: string }[] | undefined) ?? []).map(
|
|
162
|
+
(d) => `${d.recipient}: ${d.state}`,
|
|
163
|
+
);
|
|
164
|
+
lines.push(`message ${String(r.messageId)} thread ${String(r.threadId)} seq ${String(r.seq)}`);
|
|
165
|
+
return lines.join("\n");
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function fmtOverview(status: Json, groups: unknown): string {
|
|
169
|
+
const peers = (status.peers as Json[] | undefined) ?? [];
|
|
170
|
+
const lines = peers.map(
|
|
171
|
+
(p) => `${String(p.handle)} ${String(p.presence)} ${String(p.client ?? "-")} unread ${String(p.unread)}`,
|
|
172
|
+
);
|
|
173
|
+
const gs = Array.isArray(groups) ? (groups as Json[]) : [];
|
|
174
|
+
for (const g of gs) lines.push(`${String(g.name)}: ${((g.members as string[]) ?? []).join(", ")}`);
|
|
175
|
+
return lines.join("\n") || "no peers or groups";
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ---------------------------------------------------------------------------
|
|
179
|
+
|
|
180
|
+
export default function murmur(pi: ExtensionAPI): void {
|
|
181
|
+
let client: Client | undefined;
|
|
182
|
+
let closed = false; // session shut down - stop reconnecting
|
|
183
|
+
let busy = false;
|
|
184
|
+
let handle = "";
|
|
185
|
+
let announcedHandle = false;
|
|
186
|
+
let sessionId = "";
|
|
187
|
+
let sessionCtx: ExtensionContext | undefined;
|
|
188
|
+
let host: Host | undefined;
|
|
189
|
+
let reconnectTimer: ReturnType<typeof setTimeout> | undefined;
|
|
190
|
+
|
|
191
|
+
function sessionFrame(event: string): Json {
|
|
192
|
+
const cwd = sessionCtx?.cwd ?? process.cwd();
|
|
193
|
+
const frame: Json = {
|
|
194
|
+
type: "session",
|
|
195
|
+
event,
|
|
196
|
+
client: "hummin",
|
|
197
|
+
cliSessionId: sessionId,
|
|
198
|
+
host,
|
|
199
|
+
cwd,
|
|
200
|
+
listen: true,
|
|
201
|
+
};
|
|
202
|
+
const file = sessionCtx?.sessionManager.getSessionFile();
|
|
203
|
+
if (file) frame.transcriptPath = file;
|
|
204
|
+
return frame;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function quiet(p: Promise<unknown> | undefined): void {
|
|
208
|
+
p?.catch(() => {});
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function onEvent(f: Json): void {
|
|
212
|
+
const payload = f.payload as Json | Json[] | undefined;
|
|
213
|
+
if (f.event === "push" && payload && !Array.isArray(payload)) {
|
|
214
|
+
const message = payload.message as { id?: number } | undefined;
|
|
215
|
+
if (typeof payload.text !== "string" || typeof message?.id !== "number") return;
|
|
216
|
+
const deliverAs = sessionCtx?.isIdle() === false ? "steer" : "followUp";
|
|
217
|
+
try {
|
|
218
|
+
pi.sendUserMessage(payload.text, { deliverAs, expandPromptTemplates: false });
|
|
219
|
+
} catch {
|
|
220
|
+
return; // not injected: leave it undelivered so the broker can retry
|
|
221
|
+
}
|
|
222
|
+
quiet(client?.request({ type: "delivered", ids: [message.id] }));
|
|
223
|
+
} else if (f.event === "notification" && Array.isArray(payload)) {
|
|
224
|
+
if (sessionCtx?.isIdle() === false) return;
|
|
225
|
+
const details = payload.map((n) => String(n.detail ?? "")).filter(Boolean);
|
|
226
|
+
if (details.length === 0) return;
|
|
227
|
+
try {
|
|
228
|
+
pi.sendUserMessage("[murmur notice] " + details.join("; "), { deliverAs: "followUp", expandPromptTemplates: false });
|
|
229
|
+
} catch {
|
|
230
|
+
// dropped
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function scheduleReconnect(): void {
|
|
236
|
+
if (closed) return;
|
|
237
|
+
if (reconnectTimer) clearTimeout(reconnectTimer);
|
|
238
|
+
reconnectTimer = setTimeout(() => void connectBus(), RECONNECT_MS);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
async function connectBus(): Promise<void> {
|
|
242
|
+
if (closed) return;
|
|
243
|
+
try {
|
|
244
|
+
const c = await openClient(onEvent, () => {
|
|
245
|
+
if (client === c) client = undefined;
|
|
246
|
+
scheduleReconnect();
|
|
247
|
+
});
|
|
248
|
+
client = c;
|
|
249
|
+
const r = (await c.request(sessionFrame("session-start"))) as { handle?: string } | null;
|
|
250
|
+
if (r?.handle) handle = r.handle;
|
|
251
|
+
if (busy) quiet(c.request(sessionFrame("prompt")));
|
|
252
|
+
if (handle && !announcedHandle) {
|
|
253
|
+
announcedHandle = true;
|
|
254
|
+
sessionCtx?.ui.notify(`murmur: joined as ${handle}`, "info");
|
|
255
|
+
}
|
|
256
|
+
} catch {
|
|
257
|
+
client?.close();
|
|
258
|
+
client = undefined;
|
|
259
|
+
scheduleReconnect();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async function call(body: Json, timeoutMs?: number): Promise<ReturnType<typeof text>> {
|
|
264
|
+
if (!client) return text("murmur broker is not connected (retrying every 5s).", true);
|
|
265
|
+
try {
|
|
266
|
+
const r = await client.request(body, timeoutMs);
|
|
267
|
+
return text(JSON.stringify(r ?? null));
|
|
268
|
+
} catch (e) {
|
|
269
|
+
return text(String(e instanceof Error ? e.message : e), true);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// one short cli connection for the /murmur command
|
|
274
|
+
async function oneShot(run: (c: Client) => Promise<string>): Promise<string> {
|
|
275
|
+
let c: Client | undefined;
|
|
276
|
+
try {
|
|
277
|
+
c = await openClient(() => {}, () => {});
|
|
278
|
+
await c.request({ type: "register", clientKind: "cli", owner: true });
|
|
279
|
+
return await run(c);
|
|
280
|
+
} catch (e) {
|
|
281
|
+
return `murmur: ${String(e instanceof Error ? e.message : e)}`;
|
|
282
|
+
} finally {
|
|
283
|
+
c?.close();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// -------------------------------------------------------------------------
|
|
288
|
+
|
|
289
|
+
pi.on("session_start", (_event, ctx) => {
|
|
290
|
+
sessionCtx = ctx;
|
|
291
|
+
sessionId = ctx.sessionManager.getSessionId();
|
|
292
|
+
host = readHost();
|
|
293
|
+
void connectBus();
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
pi.on("agent_start", () => {
|
|
297
|
+
busy = true;
|
|
298
|
+
if (client) quiet(client.request(sessionFrame("prompt")));
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
pi.on("agent_end", () => {
|
|
302
|
+
busy = false;
|
|
303
|
+
if (client) quiet(client.request(sessionFrame("stop")));
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
pi.on("session_shutdown", () => {
|
|
307
|
+
closed = true;
|
|
308
|
+
if (reconnectTimer) clearTimeout(reconnectTimer);
|
|
309
|
+
const c = client;
|
|
310
|
+
client = undefined;
|
|
311
|
+
if (!c) return;
|
|
312
|
+
c.request(sessionFrame("session-end"), 2000)
|
|
313
|
+
.catch(() => {})
|
|
314
|
+
.finally(() => c.close());
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
pi.registerCommand("murmur", {
|
|
318
|
+
description: "Send to murmur peers or groups: /murmur <targets> <message>; bare shows peers and groups",
|
|
319
|
+
async handler(args, ctx) {
|
|
320
|
+
const trimmed = args.trim();
|
|
321
|
+
const out = await oneShot(async (c) => {
|
|
322
|
+
if (!trimmed) {
|
|
323
|
+
const status = (await c.request({ type: "status" })) as Json;
|
|
324
|
+
const groups = await c.request({ type: "groups", action: "list" });
|
|
325
|
+
return fmtOverview(status, groups);
|
|
326
|
+
}
|
|
327
|
+
const m = /^(\S+)\s+([\s\S]+)$/.exec(trimmed);
|
|
328
|
+
if (!m) return "usage: /murmur <handle|group[,handle|group...]> <message>";
|
|
329
|
+
const to = m[1]!.split(",").filter(Boolean);
|
|
330
|
+
const r = (await c.request({ type: "send", threadId: null, to, body: m[2]! })) as Json;
|
|
331
|
+
return fmtDeliveries(r);
|
|
332
|
+
});
|
|
333
|
+
ctx.ui.notify(out, out.startsWith("murmur:") || out.startsWith("usage:") ? "error" : "info");
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
const send = Type.Object({
|
|
338
|
+
to: Type.Array(Type.String(), { description: "Peer handles or group names" }),
|
|
339
|
+
body: Type.String({ minLength: 1 }),
|
|
340
|
+
threadId: Type.Optional(Type.Number({ description: "Existing thread to continue" })),
|
|
341
|
+
references: Type.Optional(Type.Array(Type.String())),
|
|
342
|
+
mode: Type.Optional(Type.Union([Type.Literal("push"), Type.Literal("notify"), Type.Literal("silent")])),
|
|
343
|
+
});
|
|
344
|
+
pi.registerTool({
|
|
345
|
+
name: "murmur_send",
|
|
346
|
+
label: "Murmur Send",
|
|
347
|
+
description: "Send a message to murmur peers or groups, optionally into an existing thread.",
|
|
348
|
+
promptSnippet: "murmur_send: message other agent sessions over the murmur bus",
|
|
349
|
+
parameters: send,
|
|
350
|
+
async execute(_id, p) {
|
|
351
|
+
return call({
|
|
352
|
+
type: "send",
|
|
353
|
+
threadId: p.threadId ?? null,
|
|
354
|
+
to: p.to,
|
|
355
|
+
body: p.body,
|
|
356
|
+
...(p.references ? { references: p.references } : {}),
|
|
357
|
+
...(p.mode ? { mode: p.mode } : {}),
|
|
358
|
+
});
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
pi.registerTool({
|
|
363
|
+
name: "murmur_reply",
|
|
364
|
+
label: "Murmur Reply",
|
|
365
|
+
description:
|
|
366
|
+
"Reply to a murmur message; the reply reaches everyone in the thread, so start the body with AGREE, DISAGREE or INFO.",
|
|
367
|
+
promptSnippet: "murmur_reply: answer a [murmur m<id>] message",
|
|
368
|
+
parameters: Type.Object({
|
|
369
|
+
messageId: Type.Number({ description: "Id from the [murmur m<id>] tag" }),
|
|
370
|
+
body: Type.String({ minLength: 1 }),
|
|
371
|
+
verdict: Type.Optional(Type.Union([Type.Literal("agree"), Type.Literal("disagree"), Type.Literal("info")])),
|
|
372
|
+
references: Type.Optional(Type.Array(Type.String())),
|
|
373
|
+
}),
|
|
374
|
+
async execute(_id, p) {
|
|
375
|
+
return call({
|
|
376
|
+
type: "reply",
|
|
377
|
+
messageId: p.messageId,
|
|
378
|
+
body: p.body,
|
|
379
|
+
...(p.verdict ? { verdict: p.verdict } : {}),
|
|
380
|
+
...(p.references ? { references: p.references } : {}),
|
|
381
|
+
});
|
|
382
|
+
},
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
pi.registerTool({
|
|
386
|
+
name: "murmur_thread",
|
|
387
|
+
label: "Murmur Thread",
|
|
388
|
+
description: "Read a murmur thread, as a digest or with full bodies.",
|
|
389
|
+
parameters: Type.Object({
|
|
390
|
+
threadId: Type.Number(),
|
|
391
|
+
sinceSeq: Type.Optional(Type.Number()),
|
|
392
|
+
full: Type.Optional(Type.Boolean()),
|
|
393
|
+
}),
|
|
394
|
+
async execute(_id, p) {
|
|
395
|
+
return call({ type: "thread", threadId: p.threadId, sinceSeq: p.sinceSeq ?? null, full: p.full ?? false });
|
|
396
|
+
},
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
pi.registerTool({
|
|
400
|
+
name: "murmur_wait",
|
|
401
|
+
label: "Murmur Wait",
|
|
402
|
+
description: "Wait until all or any recipients of a thread have replied (default 120000 ms, max 300000, 0 returns now).",
|
|
403
|
+
parameters: Type.Object({
|
|
404
|
+
threadId: Type.Number(),
|
|
405
|
+
until: Type.Union([Type.Literal("all_replied"), Type.Literal("any_replied")]),
|
|
406
|
+
timeoutMs: Type.Optional(Type.Number({ minimum: 0, maximum: 300_000 })),
|
|
407
|
+
}),
|
|
408
|
+
async execute(_id, p) {
|
|
409
|
+
const timeoutMs = Math.min(p.timeoutMs ?? 120_000, 300_000);
|
|
410
|
+
return call({ type: "wait", threadId: p.threadId, until: p.until, timeoutMs }, timeoutMs + 10_000);
|
|
411
|
+
},
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
pi.registerTool({
|
|
415
|
+
name: "murmur_status",
|
|
416
|
+
label: "Murmur Status",
|
|
417
|
+
description: "List murmur peers with presence and unread counts.",
|
|
418
|
+
parameters: Type.Object({}),
|
|
419
|
+
async execute() {
|
|
420
|
+
return call({ type: "status" });
|
|
421
|
+
},
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
pi.registerTool({
|
|
425
|
+
name: "murmur_groups",
|
|
426
|
+
label: "Murmur Groups",
|
|
427
|
+
description: "Create, list, edit or delete murmur groups.",
|
|
428
|
+
parameters: Type.Object({
|
|
429
|
+
action: Type.Union([
|
|
430
|
+
Type.Literal("create"),
|
|
431
|
+
Type.Literal("list"),
|
|
432
|
+
Type.Literal("add"),
|
|
433
|
+
Type.Literal("remove"),
|
|
434
|
+
Type.Literal("delete"),
|
|
435
|
+
]),
|
|
436
|
+
name: Type.Optional(Type.String()),
|
|
437
|
+
members: Type.Optional(Type.Array(Type.String())),
|
|
438
|
+
}),
|
|
439
|
+
async execute(_id, p) {
|
|
440
|
+
return call({
|
|
441
|
+
type: "groups",
|
|
442
|
+
action: p.action,
|
|
443
|
+
...(p.name ? { name: p.name } : {}),
|
|
444
|
+
...(p.members ? { members: p.members } : {}),
|
|
445
|
+
});
|
|
446
|
+
},
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
pi.registerTool({
|
|
450
|
+
name: "murmur_name",
|
|
451
|
+
label: "Murmur Name",
|
|
452
|
+
description: "Rename this session's murmur handle.",
|
|
453
|
+
parameters: Type.Object({ handle: Type.String({ minLength: 1 }) }),
|
|
454
|
+
async execute(_id, p) {
|
|
455
|
+
const res = await call({ type: "register", clientKind: "adapter", host, handle: p.handle });
|
|
456
|
+
if (!res.isError) {
|
|
457
|
+
try {
|
|
458
|
+
const r = JSON.parse(res.content[0]!.text) as { handle?: string } | null;
|
|
459
|
+
if (r?.handle) handle = r.handle;
|
|
460
|
+
} catch {
|
|
461
|
+
// keep the old handle
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return res;
|
|
465
|
+
},
|
|
466
|
+
});
|
|
467
|
+
}
|