@narumitw/pi-chat 0.1.4 → 0.1.6
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/README.md +30 -30
- package/dist/chunks/{menu-2XYZAYXF.js → menu-2KEDM6NJ.js} +3 -3
- package/dist/chunks/{menu-2XYZAYXF.js.map → menu-2KEDM6NJ.js.map} +2 -2
- package/dist/index.ts +2 -4
- package/dist/index.ts.map +2 -2
- package/package.json +7 -10
- package/src/menu.ts +2 -2
- package/src/pi-chat.ts +1 -4
package/README.md
CHANGED
|
@@ -2,39 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@narumitw/pi-chat) [](https://pi.dev) [](./LICENSE)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
> It is not an anonymous or reliable messaging service.
|
|
5
|
+
Join ephemeral peer-to-peer chat rooms without leaving Pi.
|
|
6
|
+
Chat messages stay out of prompts, model context, repositories, and agent output.
|
|
7
|
+
Pi Chat is not an anonymous or reliable messaging service.
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
Pi Chat discovers peers with Hyperswarm and HyperDHT and connects them through encrypted Noise streams.
|
|
9
|
+
Pi Chat uses Hyperswarm and HyperDHT for peer discovery and encrypted Noise streams for direct connections.
|
|
13
10
|
|
|
14
11
|
## ✨ Features
|
|
15
12
|
|
|
16
|
-
- Creates private rooms with bearer invites
|
|
17
|
-
- Shows stable public-key fingerprints beside nicknames
|
|
18
|
-
- Keeps chat in a dedicated composer and
|
|
19
|
-
- Preserves drafts and
|
|
20
|
-
- Signs and relays bounded events over authenticated encrypted peer connections.
|
|
21
|
-
- Stores identity settings privately and
|
|
13
|
+
- Creates private rooms with bearer invites and joins discoverable public rooms by slug.
|
|
14
|
+
- Shows stable public-key fingerprints beside nicknames for identity checks.
|
|
15
|
+
- Keeps chat in a dedicated composer and dock beside the normal Pi editor.
|
|
16
|
+
- Preserves drafts and can restore a remembered room and the last selected surface.
|
|
17
|
+
- Signs and relays bounded events over authenticated, encrypted peer connections.
|
|
18
|
+
- Stores identity settings privately and releases networking and UI resources on leave or shutdown.
|
|
22
19
|
|
|
23
20
|
## 📦 Install
|
|
24
21
|
|
|
25
|
-
Install persistently
|
|
22
|
+
Install persistently:
|
|
26
23
|
|
|
27
24
|
```bash
|
|
28
25
|
pi install npm:@narumitw/pi-chat
|
|
29
26
|
```
|
|
30
27
|
|
|
31
|
-
|
|
28
|
+
Run once from npm:
|
|
32
29
|
|
|
33
30
|
```bash
|
|
34
31
|
pi -e npm:@narumitw/pi-chat
|
|
35
32
|
```
|
|
36
33
|
|
|
37
|
-
|
|
34
|
+
Build and run a local checkout:
|
|
38
35
|
|
|
39
36
|
```bash
|
|
40
37
|
npm --workspace @narumitw/pi-chat run build
|
|
@@ -43,16 +40,16 @@ pi --no-extensions --no-skills --no-session -e ./packages/pi-chat
|
|
|
43
40
|
|
|
44
41
|
The package declares `dist/index.ts`, so an unbuilt local checkout must be built before Pi loads the package directory.
|
|
45
42
|
|
|
46
|
-
Load the package only once
|
|
47
|
-
Repeating `-e ./packages/pi-chat` creates duplicate
|
|
43
|
+
Load the package only once in each Pi process.
|
|
44
|
+
Repeating `-e ./packages/pi-chat` creates duplicate instances and suffixed commands such as `/chat:1` and `/chat:2`.
|
|
48
45
|
|
|
49
46
|
Pi extensions execute with your user permissions.
|
|
50
47
|
Review source before installing third-party packages.
|
|
51
48
|
|
|
52
49
|
## 🚀 Quick start
|
|
53
50
|
|
|
54
|
-
Run `/chat`, choose a public or private room,
|
|
55
|
-
Press `Escape` or `Ctrl+C` to return to the Pi editor
|
|
51
|
+
Run `/chat`, choose a public or private room, confirm a nickname, and start chatting.
|
|
52
|
+
Press `Escape` or `Ctrl+C` to return to the Pi editor while staying in the room and keeping the draft.
|
|
56
53
|
|
|
57
54
|
## 🧭 Rooms and composer
|
|
58
55
|
|
|
@@ -62,15 +59,16 @@ The `/chat` menu offers these entry actions:
|
|
|
62
59
|
- **Join public room** accepts a lowercase slug such as `pi-dev`, remembers it after the public-room warning is confirmed, and opens the chat composer.
|
|
63
60
|
- **Join with invite** accepts a private-room invite, then offers **Join and remember**, **Join once**, or **Cancel** before networking starts.
|
|
64
61
|
- **Create private room** generates a random `pichat:v2:…` bearer invite and uses the same explicit persistence choice.
|
|
65
|
-
Existing `pichat:v1`
|
|
62
|
+
Existing `pichat:v1` invites remain accepted and map to v2 rooms.
|
|
66
63
|
|
|
67
64
|
The first join asks for a nickname and joined-room display mode, then previews the generated identity fingerprint and display choice before one atomic save.
|
|
68
65
|
Pi Chat does not read your OS username, Git identity, cwd, repository, or Pi session to fill these values.
|
|
69
66
|
Cancelling creates neither identity settings nor network activity.
|
|
70
67
|
|
|
71
|
-
A
|
|
72
|
-
On the next Pi start, Pi Chat reconnects and
|
|
73
|
-
If you
|
|
68
|
+
A remembered join stores the room and `chat` surface atomically.
|
|
69
|
+
On the next Pi start, Pi Chat reconnects and opens the full composer without another command.
|
|
70
|
+
If you press Escape or Ctrl+C to return to Pi, it remembers the `pi` surface instead.
|
|
71
|
+
The next start then reconnects in the background and keeps the Pi editor focused.
|
|
74
72
|
|
|
75
73
|
While connected, `/chat` opens the state-aware manager.
|
|
76
74
|
**Open chat in <room>** is selected first, followed by participants, private invite, settings, status, help, and **Leave and forget room** last.
|
|
@@ -85,7 +83,7 @@ Inside the dedicated chat composer:
|
|
|
85
83
|
- `Escape` or `Ctrl+C` returns to Pi/LLM without leaving the room or discarding the chat draft.
|
|
86
84
|
|
|
87
85
|
The composer retains the draft when no authenticated direct neighbor is available or a relay reaches zero neighbors.
|
|
88
|
-
A successful local
|
|
86
|
+
A successful local send reports how many direct neighbors accepted the first relay, not room-wide delivery.
|
|
89
87
|
Signed events may arrive over multiple paths, but each client displays and forwards one `originPublicKey:eventId` only once while it remains in the bounded deduplication window.
|
|
90
88
|
Pi Chat never claims exactly-once delivery, delivery receipts, or offline retry.
|
|
91
89
|
|
|
@@ -218,7 +216,7 @@ Hyperswarm's default DHT depends on public bootstrap infrastructure. “P2P” d
|
|
|
218
216
|
NAT, UDP blocking, enterprise firewalls, bootstrap availability, peer churn, or a partitioned sparse overlay can prevent connectivity or delivery.
|
|
219
217
|
Pi Chat performs bounded refresh and reconnect work but cannot promise a connection or room-wide delivery.
|
|
220
218
|
|
|
221
|
-
## 🔒
|
|
219
|
+
## 🔒 Security and privacy
|
|
222
220
|
|
|
223
221
|
- Noise encrypts direct transport, but DHT infrastructure and direct peers may observe IP addresses, timing, and topic participation metadata.
|
|
224
222
|
Pi Chat does not provide anonymity.
|
|
@@ -235,6 +233,8 @@ Pi Chat performs bounded refresh and reconnect work but cannot promise a connect
|
|
|
235
233
|
- Chat messages never call Pi message APIs and never enter model context or the main transcript.
|
|
236
234
|
- Deleting `pi-chat.json` loses identity continuity and produces a new fingerprint on the next confirmed join.
|
|
237
235
|
|
|
236
|
+
### Recovery
|
|
237
|
+
|
|
238
238
|
If an ordinary join fails, Pi Chat tears down partially opened discovery and sockets and preserves the previous valid settings.
|
|
239
239
|
If startup restore fails, the remembered room is kept and `/chat` shows Retry, Join another room, and Forget recovery actions instead of retrying forever.
|
|
240
240
|
Invalid settings must be fixed manually before a save can proceed.
|
|
@@ -245,7 +245,7 @@ Explicit **Leave and forget room** atomically removes resume state before discon
|
|
|
245
245
|
|
|
246
246
|
## 🚧 Limitations
|
|
247
247
|
|
|
248
|
-
The current
|
|
248
|
+
The current release intentionally omits:
|
|
249
249
|
|
|
250
250
|
- simultaneous multi-room connections or UI;
|
|
251
251
|
- persistent or synchronized history;
|
|
@@ -257,10 +257,10 @@ The current experimental release intentionally omits:
|
|
|
257
257
|
- more than 256 tracked remote participants or 8 direct neighbors per client;
|
|
258
258
|
- automatic transfer of chat content into the Pi editor, transcript, or model context.
|
|
259
259
|
|
|
260
|
-
|
|
261
|
-
Selecting **Reply in <room>**
|
|
260
|
+
A joined room uses a persistent read-only widget while the normal Pi view is active.
|
|
261
|
+
Selecting **Reply in <room>** opens the full chat view instead of a small floating window.
|
|
262
262
|
Closing it returns to Pi and the dock without leaving the room.
|
|
263
|
-
|
|
263
|
+
On short terminals, the dock and composer reduce message rows before hiding room, connectivity, or input-target status.
|
|
264
264
|
|
|
265
265
|
Pi's public extension widget API does not provide generic mouse hit-testing, so the dock is not clickable and Pi Chat registers no global shortcut.
|
|
266
266
|
`/chat` remains the menu-first entrypoint.
|
|
@@ -289,7 +289,7 @@ function createChatMenu(source) {
|
|
|
289
289
|
kind: "detail",
|
|
290
290
|
title: "Pi Chat help",
|
|
291
291
|
lines: [
|
|
292
|
-
"Pi Chat is
|
|
292
|
+
"Pi Chat is TUI-only.",
|
|
293
293
|
"Chat stays outside Pi sessions, prompts, model context, and repository files.",
|
|
294
294
|
"Private invites are bearer secrets. Public rooms are guessable.",
|
|
295
295
|
"Noise encrypts direct streams, but peers and DHT infrastructure may observe network metadata.",
|
|
@@ -414,7 +414,7 @@ function mainScreen(state) {
|
|
|
414
414
|
return {
|
|
415
415
|
kind: "actions",
|
|
416
416
|
title: "Pi Chat \xB7 disconnected",
|
|
417
|
-
lines: ["
|
|
417
|
+
lines: ["Peer-to-peer chat whose messages never enter model context."],
|
|
418
418
|
items: [
|
|
419
419
|
{
|
|
420
420
|
id: "browse",
|
|
@@ -484,4 +484,4 @@ export {
|
|
|
484
484
|
createChatMenu,
|
|
485
485
|
showChatMenu
|
|
486
486
|
};
|
|
487
|
-
//# sourceMappingURL=menu-
|
|
487
|
+
//# sourceMappingURL=menu-2KEDM6NJ.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/menu.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport type { MenuDefinition } from \"@narumitw/pi-tui-kit\";\nimport type { ChatSnapshot } from \"./chat-session.js\";\nimport { normalizeNickname } from \"./nickname.js\";\nimport { type PublicRoomBrowseResult, sortDirectoryRooms } from \"./public-room-directory.js\";\nimport { createPublicRoom, parseInvite, type RoomDescriptor } from \"./room.js\";\nimport { type ChatSettings, descriptorFromRememberedRoom, type WidgetMode } from \"./settings.js\";\nimport { sanitizeSingleLine } from \"./text.js\";\n\nexport interface JoinRoomOptions {\n\tremember: boolean;\n}\n\nexport interface ChatMenuSource {\n\tsettingsPath: string;\n\tgetSettings(): ChatSettings;\n\tgetSnapshot(): ChatSnapshot | undefined;\n\tgetRestoreError(): string | undefined;\n\tcreatePrivateRoom(): RoomDescriptor;\n\tbrowsePublicRooms(signal: AbortSignal): Promise<PublicRoomBrowseResult>;\n\tjoinRoom(\n\t\troom: RoomDescriptor,\n\t\tctx: ExtensionCommandContext,\n\t\tsignal: AbortSignal,\n\t\toptions?: JoinRoomOptions,\n\t): Promise<boolean>;\n\topenChat(ctx: ExtensionCommandContext): Promise<void>;\n\tretryRememberedRoom(ctx: ExtensionCommandContext, signal: AbortSignal): Promise<void>;\n\tforgetRememberedRoom(signal: AbortSignal): Promise<void>;\n\tleaveRoom(signal: AbortSignal): Promise<void>;\n\ttoggleMute(publicKey: string): boolean | undefined;\n\tupdateNickname(value: string, signal: AbortSignal): Promise<void>;\n\tupdateWidgetMode(value: WidgetMode, signal: AbortSignal): Promise<void>;\n\tgetIdentityResetPreview(): { current: string; next: string };\n\tresetIdentity(signal: AbortSignal): Promise<void>;\n}\n\ninterface ChatMenuState {\n\tsettings: ChatSettings;\n\tsnapshot?: ChatSnapshot;\n\tpendingRoom?: RoomDescriptor;\n\trestoreError?: string;\n\tdirectoryResult?: PublicRoomBrowseResult;\n\tdirectoryError?: string;\n}\n\ntype Screen =\n\t| \"main\"\n\t| \"invite\"\n\t| \"joinInvite\"\n\t| \"joinPublic\"\n\t| \"publicRooms\"\n\t| \"joinAnother\"\n\t| \"participants\"\n\t| \"settings\"\n\t| \"changeNickname\"\n\t| \"widget\"\n\t| \"resetIdentity\"\n\t| \"leave\"\n\t| \"forget\"\n\t| \"status\"\n\t| \"help\";\ntype Action =\n\t| \"createPrivate\"\n\t| \"joinPending\"\n\t| \"joinInvite\"\n\t| \"joinPublic\"\n\t| \"browse\"\n\t| \"selectPublicRoom\"\n\t| \"retry\"\n\t| \"forget\"\n\t| \"open\"\n\t| \"leave\"\n\t| \"toggleMute\"\n\t| \"changeNickname\"\n\t| \"setWidget\"\n\t| \"resetIdentity\";\n\nexport function createChatMenu(source: ChatMenuSource) {\n\tlet pendingRoom: RoomDescriptor | undefined;\n\tlet directoryResult: PublicRoomBrowseResult | undefined;\n\tlet directoryError: string | undefined;\n\tconst getState = async (): Promise<ChatMenuState> => ({\n\t\tsettings: source.getSettings(),\n\t\tsnapshot: source.getSnapshot(),\n\t\tpendingRoom,\n\t\t...(source.getRestoreError() ? { restoreError: source.getRestoreError() } : {}),\n\t\t...(directoryResult ? { directoryResult } : {}),\n\t\t...(directoryError ? { directoryError } : {}),\n\t});\n\tconst browseRooms = async (signal: AbortSignal) => {\n\t\ttry {\n\t\t\tconst result = await source.browsePublicRooms(signal);\n\t\t\tif (signal.aborted) return { kind: \"stay\" as const };\n\t\t\tdirectoryResult = { ...result, rooms: sortDirectoryRooms(result.rooms) };\n\t\t\tdirectoryError = undefined;\n\t\t} catch (error) {\n\t\t\tif (signal.aborted) return { kind: \"stay\" as const };\n\t\t\tdirectoryResult = undefined;\n\t\t\tdirectoryError = sanitizeSingleLine(error instanceof Error ? error.message : String(error));\n\t\t}\n\t\treturn { kind: \"to\" as const, screen: \"publicRooms\" as const };\n\t};\n\tconst joinPublic = async (slug: string, ctx: ExtensionCommandContext, signal: AbortSignal) => {\n\t\tlet room: RoomDescriptor;\n\t\ttry {\n\t\t\troom = createPublicRoom(slug.replace(/^#/u, \"\"));\n\t\t} catch (error) {\n\t\t\treturn { kind: \"rejected\" as const, error };\n\t\t}\n\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t\"Join public room?\",\n\t\t\t\"Anyone can join or record it. DHT and direct peers may observe network metadata.\",\n\t\t\t{ signal },\n\t\t);\n\t\tif (!confirmed || signal.aborted) return { kind: \"stay\" as const };\n\t\tif (!(await source.joinRoom(room, ctx, signal, { remember: true })) || signal.aborted) {\n\t\t\treturn { kind: \"stay\" as const };\n\t\t}\n\t\tawait source.openChat(ctx);\n\t\treturn { kind: \"close\" as const };\n\t};\n\tconst menu: MenuDefinition<ChatMenuState, Screen, Action> = {\n\t\tstart: \"main\",\n\t\tscreens: {\n\t\t\tmain: ({ state }) => mainScreen(state),\n\t\t\tinvite: ({ state }) => {\n\t\t\t\tconst room = state.pendingRoom ?? state.snapshot?.room;\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"review\",\n\t\t\t\t\ttitle: \"Private room invite\",\n\t\t\t\t\tlines: [\n\t\t\t\t\t\t\"Anyone with this bearer invite can join.\",\n\t\t\t\t\t\t\"After confirmation, choose whether to save it privately for restart restore.\",\n\t\t\t\t\t],\n\t\t\t\t\tcontent: room?.invite ?? \"Invite is unavailable.\",\n\t\t\t\t\tformat: { kind: \"text\" },\n\t\t\t\t\tviewportSize: \"adaptive\",\n\t\t\t\t\t...(state.pendingRoom\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tconfirm: {\n\t\t\t\t\t\t\t\t\tid: \"join-private\",\n\t\t\t\t\t\t\t\t\tlabel: \"Join private room\",\n\t\t\t\t\t\t\t\t\taction: \"joinPending\" as const,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: {}),\n\t\t\t\t\thint: \"back\",\n\t\t\t\t};\n\t\t\t},\n\t\t\tjoinInvite: () => ({\n\t\t\t\tkind: \"input\",\n\t\t\t\ttitle: \"Join with invite\",\n\t\t\t\tlines: [\n\t\t\t\t\t\"Paste a pichat:v1 or pichat:v2 invite. It grants access to the private room.\",\n\t\t\t\t\t\"You will choose Join and remember, Join once, or Cancel before networking starts.\",\n\t\t\t\t],\n\t\t\t\tplaceholder: \"pichat:v2:\u2026\",\n\t\t\t\taction: \"joinInvite\",\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\tjoinPublic: () => ({\n\t\t\t\tkind: \"input\",\n\t\t\t\ttitle: \"Join public room\",\n\t\t\t\tlines: [\"Use a lowercase room slug. Public rooms are guessable and open to anyone.\"],\n\t\t\t\tplaceholder: \"pi-dev\",\n\t\t\t\taction: \"joinPublic\",\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\tpublicRooms: ({ state }) => {\n\t\t\t\tconst rooms = state.directoryResult?.rooms ?? [];\n\t\t\t\tconst lines = state.directoryError\n\t\t\t\t\t? [\n\t\t\t\t\t\t\t`Discovery failed: ${sanitizeSingleLine(state.directoryError)}`,\n\t\t\t\t\t\t\t\"Retry or enter a known public room slug.\",\n\t\t\t\t\t\t]\n\t\t\t\t\t: rooms.length === 0\n\t\t\t\t\t\t? [\"No active public rooms were discovered. Counts are best-effort estimates.\"]\n\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\tstate.directoryResult?.partial\n\t\t\t\t\t\t\t\t\t? \"Estimated active participants \u00B7 partial discovered results.\"\n\t\t\t\t\t\t\t\t\t: \"Estimated active participants \u00B7 currently discovered results.\",\n\t\t\t\t\t\t\t\t\"Select a room to review the public-room warning before joining.\",\n\t\t\t\t\t\t\t];\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"choice\",\n\t\t\t\t\ttitle: \"Public rooms\",\n\t\t\t\t\tlines,\n\t\t\t\t\titems: [\n\t\t\t\t\t\t...rooms.map((room) => ({\n\t\t\t\t\t\t\tid: `room:${room.slug}`,\n\t\t\t\t\t\t\tlabel: `#${room.slug}`,\n\t\t\t\t\t\t\tdescription: `~${room.estimatedParticipants} active`,\n\t\t\t\t\t\t\tdetails: [\"Estimated from recent signed P2P directory presence.\"],\n\t\t\t\t\t\t})),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"route:refresh\",\n\t\t\t\t\t\t\tlabel: state.directoryError ? \"Retry discovery\" : \"Refresh discovery\",\n\t\t\t\t\t\t\tdescription: \"Query the P2P directory again\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"route:manual\",\n\t\t\t\t\t\t\tlabel: \"Enter room slug\",\n\t\t\t\t\t\t\tdescription: \"Join a known public room manually\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\taction: \"selectPublicRoom\",\n\t\t\t\t\tviewportSize: 10,\n\t\t\t\t\thint: \"back\",\n\t\t\t\t};\n\t\t\t},\n\t\t\tjoinAnother: () => ({\n\t\t\t\tkind: \"actions\",\n\t\t\t\ttitle: \"Join another room\",\n\t\t\t\tlines: [\"A successfully remembered join replaces the room restored at startup.\"],\n\t\t\t\titems: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"browse\",\n\t\t\t\t\t\tlabel: \"Browse public rooms\",\n\t\t\t\t\t\taction: \"browse\",\n\t\t\t\t\t\tbusyLabel: \"Discovering rooms\",\n\t\t\t\t\t},\n\t\t\t\t\t{ id: \"public\", label: \"Join public room\", to: \"joinPublic\" },\n\t\t\t\t\t{ id: \"invite\", label: \"Join with invite\", to: \"joinInvite\" },\n\t\t\t\t\t{ id: \"create\", label: \"Create private room\", action: \"createPrivate\" },\n\t\t\t\t],\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\tparticipants: ({ state }) => ({\n\t\t\t\tkind: \"choice\",\n\t\t\t\ttitle: \"Active participants\",\n\t\t\t\tlines: state.snapshot?.participants.length\n\t\t\t\t\t? [\"Select an origin to toggle local mute. Full public keys are shown in details.\"]\n\t\t\t\t\t: [\"No other active participants are currently discovered.\"],\n\t\t\t\titems:\n\t\t\t\t\tstate.snapshot?.participants.map((peer) => ({\n\t\t\t\t\t\tid: peer.publicKey,\n\t\t\t\t\t\tlabel: sanitizeSingleLine(peer.label),\n\t\t\t\t\t\tdescription: peer.muted ? \"Muted locally\" : \"Receiving messages\",\n\t\t\t\t\t\tdetails: [peer.publicKey],\n\t\t\t\t\t})) ?? [],\n\t\t\t\taction: \"toggleMute\",\n\t\t\t\tviewportSize: 10,\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\tsettings: ({ state }) => ({\n\t\t\t\tkind: \"actions\",\n\t\t\t\ttitle: \"Pi Chat settings\",\n\t\t\t\tlines: [\n\t\t\t\t\t`Nickname: ${sanitizeSingleLine(state.settings.nickname ?? \"not set\")}`,\n\t\t\t\t\t`Joined room display: ${state.settings.widgetMode ?? \"count\"}`,\n\t\t\t\t\t`Restart: ${restartDescription(state.settings)}`,\n\t\t\t\t\t`User settings \u00B7 ${sanitizeSingleLine(source.settingsPath)}`,\n\t\t\t\t],\n\t\t\t\titems: [\n\t\t\t\t\t{ id: \"nickname\", label: \"Change nickname\", to: \"changeNickname\" },\n\t\t\t\t\t{ id: \"widget\", label: \"Joined room display\", to: \"widget\" },\n\t\t\t\t\t{ id: \"reset\", label: \"Reset identity\u2026\", to: \"resetIdentity\" },\n\t\t\t\t],\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\tchangeNickname: () => ({\n\t\t\t\tkind: \"input\",\n\t\t\t\ttitle: \"Change nickname\",\n\t\t\t\tlines: [\"The immutable fingerprint remains attached to the new nickname.\"],\n\t\t\t\tplaceholder: \"Mika\",\n\t\t\t\taction: \"changeNickname\",\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\twidget: ({ state }) => ({\n\t\t\t\tkind: \"choice\",\n\t\t\t\ttitle: \"Joined room display\",\n\t\t\t\tlines: [\"Choose how much room content remains visible above the Pi editor.\"],\n\t\t\t\titems: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"dock\",\n\t\t\t\t\t\tlabel: \"Room dock\",\n\t\t\t\t\t\tdescription: \"Status, input target, and up to three recent messages\",\n\t\t\t\t\t},\n\t\t\t\t\t{ id: \"latest\", label: \"Latest message\", description: \"Show one recent message\" },\n\t\t\t\t\t{ id: \"count\", label: \"Status only\", description: \"Hide message text\" },\n\t\t\t\t\t{ id: \"off\", label: \"Hidden\", description: \"Show no persistent room widget\" },\n\t\t\t\t],\n\t\t\t\taction: \"setWidget\",\n\t\t\t\tcurrentItemId: state.settings.widgetMode ?? \"count\",\n\t\t\t\tinitialItemId: state.settings.widgetMode ?? \"count\",\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\tresetIdentity: () => {\n\t\t\t\tconst preview = source.getIdentityResetPreview();\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"review\",\n\t\t\t\t\ttitle: \"Reset Pi Chat identity?\",\n\t\t\t\t\tlines: [\n\t\t\t\t\t\t`Current: ${preview.current}`,\n\t\t\t\t\t\t`New: ${preview.next}`,\n\t\t\t\t\t\t\"Resetting changes your fingerprint, forgets startup restore, and leaves the room.\",\n\t\t\t\t\t],\n\t\t\t\t\tcontent: \"This cannot restore trust or blocked state associated with the old public key.\",\n\t\t\t\t\tformat: { kind: \"text\" },\n\t\t\t\t\tconfirm: { id: \"reset\", label: \"Reset identity\", action: \"resetIdentity\" },\n\t\t\t\t\thint: \"back\",\n\t\t\t\t};\n\t\t\t},\n\t\t\tleave: ({ state }) => {\n\t\t\t\tconst forgetsCurrent = state.settings.resume?.activeRoomId === state.snapshot?.room.id;\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"review\",\n\t\t\t\t\ttitle: forgetsCurrent ? \"Leave and forget room?\" : \"Leave room?\",\n\t\t\t\t\tlines: [\n\t\t\t\t\t\t`Room: ${sanitizeSingleLine(state.snapshot?.room.label ?? \"unknown\")}`,\n\t\t\t\t\t\tforgetsCurrent\n\t\t\t\t\t\t\t? \"Leaving disconnects peers, clears this transcript, and disables startup restore.\"\n\t\t\t\t\t\t\t: \"Leaving disconnects peers and clears this ephemeral transcript.\",\n\t\t\t\t\t],\n\t\t\t\t\tcontent: \"Messages already received by other peers cannot be withdrawn.\",\n\t\t\t\t\tformat: { kind: \"text\" },\n\t\t\t\t\tconfirm: {\n\t\t\t\t\t\tid: \"leave\",\n\t\t\t\t\t\tlabel: forgetsCurrent ? \"Leave and forget room\" : \"Leave room\",\n\t\t\t\t\t\taction: \"leave\",\n\t\t\t\t\t},\n\t\t\t\t\thint: \"back\",\n\t\t\t\t};\n\t\t\t},\n\t\t\tforget: ({ state }) => {\n\t\t\t\tconst room = rememberedRoom(state.settings);\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"review\",\n\t\t\t\t\ttitle: \"Forget saved room?\",\n\t\t\t\t\tlines: [\n\t\t\t\t\t\t`Room: ${sanitizeSingleLine(room?.label ?? \"unknown\")}`,\n\t\t\t\t\t\t\"Pi Chat will not reconnect to this room at startup.\",\n\t\t\t\t\t],\n\t\t\t\t\tcontent: \"This does not withdraw messages already received by peers.\",\n\t\t\t\t\tformat: { kind: \"text\" },\n\t\t\t\t\tconfirm: { id: \"forget\", label: \"Forget saved room\", action: \"forget\" },\n\t\t\t\t\thint: \"back\",\n\t\t\t\t};\n\t\t\t},\n\t\t\tstatus: ({ state }) => ({\n\t\t\t\tkind: \"detail\",\n\t\t\t\ttitle: \"Pi Chat status\",\n\t\t\t\tlines: state.snapshot\n\t\t\t\t\t? [\n\t\t\t\t\t\t\t`State: ${state.snapshot.state}`,\n\t\t\t\t\t\t\t`Room: ${sanitizeSingleLine(state.snapshot.room.label)}`,\n\t\t\t\t\t\t\t`Identity: ${sanitizeSingleLine(state.snapshot.localLabel)}`,\n\t\t\t\t\t\t\t`Active participants: ${state.snapshot.participants.length}`,\n\t\t\t\t\t\t\t`Direct neighbors: ${state.snapshot.directNeighbors}`,\n\t\t\t\t\t\t\t`Unread: ${state.snapshot.unread}`,\n\t\t\t\t\t\t\t`Restart: ${restartDescription(state.settings)}`,\n\t\t\t\t\t\t\t...(state.snapshot.lastError\n\t\t\t\t\t\t\t\t? [`Attention: ${sanitizeSingleLine(state.snapshot.lastError)}`]\n\t\t\t\t\t\t\t\t: []),\n\t\t\t\t\t\t]\n\t\t\t\t\t: [\n\t\t\t\t\t\t\t\"State: disconnected\",\n\t\t\t\t\t\t\t`Restart: ${restartDescription(state.settings)}`,\n\t\t\t\t\t\t\t...(state.restoreError\n\t\t\t\t\t\t\t\t? [`Attention: ${sanitizeSingleLine(state.restoreError)}`]\n\t\t\t\t\t\t\t\t: []),\n\t\t\t\t\t\t\t`Settings: ${sanitizeSingleLine(source.settingsPath)}`,\n\t\t\t\t\t\t],\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\thelp: () => ({\n\t\t\t\tkind: \"detail\",\n\t\t\t\ttitle: \"Pi Chat help\",\n\t\t\t\tlines: [\n\t\t\t\t\t\"Pi Chat is experimental and TUI-only.\",\n\t\t\t\t\t\"Chat stays outside Pi sessions, prompts, model context, and repository files.\",\n\t\t\t\t\t\"Private invites are bearer secrets. Public rooms are guessable.\",\n\t\t\t\t\t\"Noise encrypts direct streams, but peers and DHT infrastructure may observe network metadata.\",\n\t\t\t\t\t\"Public-room discovery and participant counts are approximate P2P observations.\",\n\t\t\t\t\t\"There is no offline delivery, global ordering, delivery receipt, or message withdrawal.\",\n\t\t\t\t],\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t},\n\t\tactions: {\n\t\t\tcreatePrivate: () => {\n\t\t\t\tpendingRoom = source.createPrivateRoom();\n\t\t\t\treturn { kind: \"to\", screen: \"invite\" };\n\t\t\t},\n\t\t\tjoinPending: async ({ ctx, signal }) => {\n\t\t\t\tif (!pendingRoom) return { kind: \"rejected\", error: new Error(\"Invite is unavailable\") };\n\t\t\t\tif (!(await source.joinRoom(pendingRoom, ctx, signal)) || signal.aborted) {\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t}\n\t\t\t\tawait source.openChat(ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tjoinInvite: async ({ ctx, signal, value }) => {\n\t\t\t\tlet room: RoomDescriptor;\n\t\t\t\ttry {\n\t\t\t\t\troom = parseInvite(value ?? \"\");\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn { kind: \"rejected\", error };\n\t\t\t\t}\n\t\t\t\tif (!(await source.joinRoom(room, ctx, signal)) || signal.aborted) return { kind: \"stay\" };\n\t\t\t\tawait source.openChat(ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tjoinPublic: ({ ctx, signal, value }) => joinPublic(value ?? \"\", ctx, signal),\n\t\t\tbrowse: ({ signal }) => browseRooms(signal),\n\t\t\tselectPublicRoom: async ({ ctx, signal, itemId }) => {\n\t\t\t\tif (itemId === \"route:refresh\") return browseRooms(signal);\n\t\t\t\tif (itemId === \"route:manual\") return { kind: \"to\", screen: \"joinPublic\" };\n\t\t\t\tif (!itemId.startsWith(\"room:\")) {\n\t\t\t\t\treturn { kind: \"rejected\", error: new Error(\"Public room selection is invalid\") };\n\t\t\t\t}\n\t\t\t\treturn joinPublic(itemId.slice(\"room:\".length), ctx, signal);\n\t\t\t},\n\t\t\tretry: async ({ ctx, signal }) => {\n\t\t\t\tawait source.retryRememberedRoom(ctx, signal);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tforget: async ({ signal }) => {\n\t\t\t\tawait source.forgetRememberedRoom(signal);\n\t\t\t\treturn { kind: \"to\", screen: \"main\" };\n\t\t\t},\n\t\t\topen: async ({ ctx }) => {\n\t\t\t\tawait source.openChat(ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tleave: async ({ signal }) => {\n\t\t\t\tawait source.leaveRoom(signal);\n\t\t\t\treturn { kind: \"to\", screen: \"main\" };\n\t\t\t},\n\t\t\ttoggleMute: ({ itemId }) => {\n\t\t\t\tconst muted = source.toggleMute(itemId);\n\t\t\t\treturn muted === undefined\n\t\t\t\t\t? { kind: \"rejected\", error: new Error(\"Peer is no longer connected\") }\n\t\t\t\t\t: { kind: \"to\", screen: \"participants\" };\n\t\t\t},\n\t\t\tchangeNickname: async ({ signal, value }) => {\n\t\t\t\tconst nickname = normalizeNickname(value);\n\t\t\t\tif (!nickname) return { kind: \"rejected\", error: new Error(\"Nickname is invalid\") };\n\t\t\t\tawait source.updateNickname(nickname, signal);\n\t\t\t\treturn { kind: \"to\", screen: \"settings\" };\n\t\t\t},\n\t\t\tsetWidget: async ({ signal, itemId }) => {\n\t\t\t\tif (itemId !== \"dock\" && itemId !== \"count\" && itemId !== \"latest\" && itemId !== \"off\") {\n\t\t\t\t\treturn { kind: \"rejected\", error: new Error(\"Widget mode is invalid\") };\n\t\t\t\t}\n\t\t\t\tawait source.updateWidgetMode(itemId, signal);\n\t\t\t\treturn { kind: \"to\", screen: \"settings\" };\n\t\t\t},\n\t\t\tresetIdentity: async ({ signal }) => {\n\t\t\t\tawait source.resetIdentity(signal);\n\t\t\t\treturn { kind: \"to\", screen: \"settings\" };\n\t\t\t},\n\t\t},\n\t};\n\treturn { menu, getState };\n}\n\nexport async function showChatMenu(\n\tctx: ExtensionCommandContext,\n\tsource: ChatMenuSource,\n\townership: { signal: AbortSignal; isCurrent: () => boolean },\n): Promise<void> {\n\tconst { runMenu } = await import(\"@narumitw/pi-tui-kit\");\n\tif (ownership.signal.aborted || !ownership.isCurrent()) return;\n\tconst controller = createChatMenu(source);\n\tawait runMenu(ctx, controller.menu, {\n\t\tgetState: controller.getState,\n\t\tsignal: ownership.signal,\n\t\tisCurrent: ownership.isCurrent,\n\t\tonError: (_ctx, error) => {\n\t\t\tif (ownership.isCurrent() && !ownership.signal.aborted) {\n\t\t\t\tctx.ui.notify(`Pi Chat failed: ${sanitizeSingleLine(safeError(error))}`, \"error\");\n\t\t\t}\n\t\t},\n\t});\n}\n\nfunction mainScreen(state: ChatMenuState) {\n\tconst remembered = rememberedRoom(state.settings);\n\tif (!state.snapshot || state.snapshot.state === \"disconnected\") {\n\t\tif (remembered) {\n\t\t\treturn {\n\t\t\t\tkind: \"actions\" as const,\n\t\t\t\ttitle: state.restoreError\n\t\t\t\t\t? `Pi Chat \u00B7 could not restore ${sanitizeSingleLine(remembered.label)}`\n\t\t\t\t\t: `Pi Chat \u00B7 ${sanitizeSingleLine(remembered.label)} remembered`,\n\t\t\t\tlines: [\n\t\t\t\t\tstate.restoreError\n\t\t\t\t\t\t? `Attention: ${sanitizeSingleLine(state.restoreError)}`\n\t\t\t\t\t\t: \"Disconnected. This room is configured to reconnect at startup.\",\n\t\t\t\t\t`Restart surface: ${state.settings.resume?.surface === \"chat\" ? \"open chat\" : \"Pi/LLM\"}`,\n\t\t\t\t],\n\t\t\t\titems: [\n\t\t\t\t\t{ id: \"retry\", label: `Retry ${remembered.label}`, action: \"retry\" as const },\n\t\t\t\t\t{ id: \"another\", label: \"Join another room\", to: \"joinAnother\" as const },\n\t\t\t\t\t{ id: \"forget\", label: `Forget ${remembered.label}\u2026`, to: \"forget\" as const },\n\t\t\t\t\t{ id: \"settings\", label: \"Settings\", to: \"settings\" as const },\n\t\t\t\t\t{ id: \"status\", label: \"Status\", to: \"status\" as const },\n\t\t\t\t\t{ id: \"help\", label: \"Help\", to: \"help\" as const },\n\t\t\t\t],\n\t\t\t\thint: \"close\" as const,\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tkind: \"actions\" as const,\n\t\t\ttitle: \"Pi Chat \u00B7 disconnected\",\n\t\t\tlines: [\"Experimental peer-to-peer chat. Messages never enter model context.\"],\n\t\t\titems: [\n\t\t\t\t{\n\t\t\t\t\tid: \"browse\",\n\t\t\t\t\tlabel: \"Browse public rooms\",\n\t\t\t\t\taction: \"browse\" as const,\n\t\t\t\t\tbusyLabel: \"Discovering rooms\",\n\t\t\t\t},\n\t\t\t\t{ id: \"public\", label: \"Join public room\", to: \"joinPublic\" as const },\n\t\t\t\t{ id: \"invite\", label: \"Join with invite\", to: \"joinInvite\" as const },\n\t\t\t\t{ id: \"create\", label: \"Create private room\", action: \"createPrivate\" as const },\n\t\t\t\t{ id: \"settings\", label: \"Settings\", to: \"settings\" as const },\n\t\t\t\t{ id: \"status\", label: \"Status\", to: \"status\" as const },\n\t\t\t\t{ id: \"help\", label: \"Help\", to: \"help\" as const },\n\t\t\t],\n\t\t\thint: \"close\" as const,\n\t\t};\n\t}\n\tconst restoresCurrent = remembered?.id === state.snapshot.room.id;\n\treturn {\n\t\tkind: \"actions\" as const,\n\t\ttitle: `Pi Chat \u00B7 ${sanitizeSingleLine(state.snapshot.room.label)}`,\n\t\tlines: [\n\t\t\t`${state.snapshot.state} \u00B7 ${state.snapshot.participants.length} active \u00B7 ${state.snapshot.directNeighbors} direct neighbors \u00B7 ${state.snapshot.unread} unread`,\n\t\t\t`Current input: ${state.snapshot.composerOpen ? state.snapshot.room.label : \"Pi/LLM\"}`,\n\t\t\trestoresCurrent\n\t\t\t\t? `Restart: restore this room and ${state.settings.resume?.surface === \"chat\" ? \"open chat\" : \"stay in Pi/LLM\"}`\n\t\t\t\t: \"Restart: this room will not reconnect\",\n\t\t\tstate.snapshot.localLabel,\n\t\t],\n\t\titems: [\n\t\t\t{\n\t\t\t\tid: \"open\",\n\t\t\t\tlabel: `Open chat in ${sanitizeSingleLine(state.snapshot.room.label)}`,\n\t\t\t\taction: \"open\" as const,\n\t\t\t},\n\t\t\t{ id: \"participants\", label: \"Show active participants\", to: \"participants\" as const },\n\t\t\t...(state.snapshot.room.invite\n\t\t\t\t? [{ id: \"invite\", label: \"Show room invite\", to: \"invite\" as const }]\n\t\t\t\t: []),\n\t\t\t{ id: \"settings\", label: \"Settings\", to: \"settings\" as const },\n\t\t\t{ id: \"status\", label: \"Status\", to: \"status\" as const },\n\t\t\t{ id: \"help\", label: \"Help\", to: \"help\" as const },\n\t\t\t{\n\t\t\t\tid: \"leave\",\n\t\t\t\tlabel: restoresCurrent ? \"Leave and forget room\u2026\" : \"Leave room\u2026\",\n\t\t\t\tto: \"leave\" as const,\n\t\t\t},\n\t\t],\n\t\thint: \"close\" as const,\n\t};\n}\n\nfunction rememberedRoom(settings: ChatSettings): RoomDescriptor | undefined {\n\tconst resume = settings.resume;\n\tconst remembered = resume?.rooms.find(({ id }) => id === resume.activeRoomId);\n\tif (!remembered) return undefined;\n\ttry {\n\t\treturn descriptorFromRememberedRoom(remembered);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction restartDescription(settings: ChatSettings): string {\n\tconst room = rememberedRoom(settings);\n\tif (!room) return \"no room remembered\";\n\treturn `${room.label} \u00B7 ${settings.resume?.surface === \"chat\" ? \"open chat\" : \"stay in Pi/LLM\"}`;\n}\n\nfunction safeError(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AA8EO,SAAS,eAAe,QAAwB;AACtD,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,QAAM,WAAW,aAAqC;AAAA,IACrD,UAAU,OAAO,YAAY;AAAA,IAC7B,UAAU,OAAO,YAAY;AAAA,IAC7B;AAAA,IACA,GAAI,OAAO,gBAAgB,IAAI,EAAE,cAAc,OAAO,gBAAgB,EAAE,IAAI,CAAC;AAAA,IAC7E,GAAI,kBAAkB,EAAE,gBAAgB,IAAI,CAAC;AAAA,IAC7C,GAAI,iBAAiB,EAAE,eAAe,IAAI,CAAC;AAAA,EAC5C;AACA,QAAM,cAAc,OAAO,WAAwB;AAClD,QAAI;AACH,YAAM,SAAS,MAAM,OAAO,kBAAkB,MAAM;AACpD,UAAI,OAAO,QAAS,QAAO,EAAE,MAAM,OAAgB;AACnD,wBAAkB,EAAE,GAAG,QAAQ,OAAO,mBAAmB,OAAO,KAAK,EAAE;AACvE,uBAAiB;AAAA,IAClB,SAAS,OAAO;AACf,UAAI,OAAO,QAAS,QAAO,EAAE,MAAM,OAAgB;AACnD,wBAAkB;AAClB,uBAAiB,mBAAmB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,IAC3F;AACA,WAAO,EAAE,MAAM,MAAe,QAAQ,cAAuB;AAAA,EAC9D;AACA,QAAM,aAAa,OAAO,MAAc,KAA8B,WAAwB;AAC7F,QAAI;AACJ,QAAI;AACH,aAAO,iBAAiB,KAAK,QAAQ,OAAO,EAAE,CAAC;AAAA,IAChD,SAAS,OAAO;AACf,aAAO,EA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,OAAO,eAAe,QAAQ;AACpC,MAAI,CAAC,KAAM,QAAO;AAClB,SAAO,GAAG,KAAK,KAAK,SAAM,SAAS,QAAQ,YAAY,SAAS,cAAc,gBAAgB;AAC/F;AAEA,SAAS,UAAU,OAAwB;AAC1C,SAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC7D;",
|
|
4
|
+
"sourcesContent": ["import type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport type { MenuDefinition } from \"@narumitw/pi-tui-kit\";\nimport type { ChatSnapshot } from \"./chat-session.js\";\nimport { normalizeNickname } from \"./nickname.js\";\nimport { type PublicRoomBrowseResult, sortDirectoryRooms } from \"./public-room-directory.js\";\nimport { createPublicRoom, parseInvite, type RoomDescriptor } from \"./room.js\";\nimport { type ChatSettings, descriptorFromRememberedRoom, type WidgetMode } from \"./settings.js\";\nimport { sanitizeSingleLine } from \"./text.js\";\n\nexport interface JoinRoomOptions {\n\tremember: boolean;\n}\n\nexport interface ChatMenuSource {\n\tsettingsPath: string;\n\tgetSettings(): ChatSettings;\n\tgetSnapshot(): ChatSnapshot | undefined;\n\tgetRestoreError(): string | undefined;\n\tcreatePrivateRoom(): RoomDescriptor;\n\tbrowsePublicRooms(signal: AbortSignal): Promise<PublicRoomBrowseResult>;\n\tjoinRoom(\n\t\troom: RoomDescriptor,\n\t\tctx: ExtensionCommandContext,\n\t\tsignal: AbortSignal,\n\t\toptions?: JoinRoomOptions,\n\t): Promise<boolean>;\n\topenChat(ctx: ExtensionCommandContext): Promise<void>;\n\tretryRememberedRoom(ctx: ExtensionCommandContext, signal: AbortSignal): Promise<void>;\n\tforgetRememberedRoom(signal: AbortSignal): Promise<void>;\n\tleaveRoom(signal: AbortSignal): Promise<void>;\n\ttoggleMute(publicKey: string): boolean | undefined;\n\tupdateNickname(value: string, signal: AbortSignal): Promise<void>;\n\tupdateWidgetMode(value: WidgetMode, signal: AbortSignal): Promise<void>;\n\tgetIdentityResetPreview(): { current: string; next: string };\n\tresetIdentity(signal: AbortSignal): Promise<void>;\n}\n\ninterface ChatMenuState {\n\tsettings: ChatSettings;\n\tsnapshot?: ChatSnapshot;\n\tpendingRoom?: RoomDescriptor;\n\trestoreError?: string;\n\tdirectoryResult?: PublicRoomBrowseResult;\n\tdirectoryError?: string;\n}\n\ntype Screen =\n\t| \"main\"\n\t| \"invite\"\n\t| \"joinInvite\"\n\t| \"joinPublic\"\n\t| \"publicRooms\"\n\t| \"joinAnother\"\n\t| \"participants\"\n\t| \"settings\"\n\t| \"changeNickname\"\n\t| \"widget\"\n\t| \"resetIdentity\"\n\t| \"leave\"\n\t| \"forget\"\n\t| \"status\"\n\t| \"help\";\ntype Action =\n\t| \"createPrivate\"\n\t| \"joinPending\"\n\t| \"joinInvite\"\n\t| \"joinPublic\"\n\t| \"browse\"\n\t| \"selectPublicRoom\"\n\t| \"retry\"\n\t| \"forget\"\n\t| \"open\"\n\t| \"leave\"\n\t| \"toggleMute\"\n\t| \"changeNickname\"\n\t| \"setWidget\"\n\t| \"resetIdentity\";\n\nexport function createChatMenu(source: ChatMenuSource) {\n\tlet pendingRoom: RoomDescriptor | undefined;\n\tlet directoryResult: PublicRoomBrowseResult | undefined;\n\tlet directoryError: string | undefined;\n\tconst getState = async (): Promise<ChatMenuState> => ({\n\t\tsettings: source.getSettings(),\n\t\tsnapshot: source.getSnapshot(),\n\t\tpendingRoom,\n\t\t...(source.getRestoreError() ? { restoreError: source.getRestoreError() } : {}),\n\t\t...(directoryResult ? { directoryResult } : {}),\n\t\t...(directoryError ? { directoryError } : {}),\n\t});\n\tconst browseRooms = async (signal: AbortSignal) => {\n\t\ttry {\n\t\t\tconst result = await source.browsePublicRooms(signal);\n\t\t\tif (signal.aborted) return { kind: \"stay\" as const };\n\t\t\tdirectoryResult = { ...result, rooms: sortDirectoryRooms(result.rooms) };\n\t\t\tdirectoryError = undefined;\n\t\t} catch (error) {\n\t\t\tif (signal.aborted) return { kind: \"stay\" as const };\n\t\t\tdirectoryResult = undefined;\n\t\t\tdirectoryError = sanitizeSingleLine(error instanceof Error ? error.message : String(error));\n\t\t}\n\t\treturn { kind: \"to\" as const, screen: \"publicRooms\" as const };\n\t};\n\tconst joinPublic = async (slug: string, ctx: ExtensionCommandContext, signal: AbortSignal) => {\n\t\tlet room: RoomDescriptor;\n\t\ttry {\n\t\t\troom = createPublicRoom(slug.replace(/^#/u, \"\"));\n\t\t} catch (error) {\n\t\t\treturn { kind: \"rejected\" as const, error };\n\t\t}\n\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t\"Join public room?\",\n\t\t\t\"Anyone can join or record it. DHT and direct peers may observe network metadata.\",\n\t\t\t{ signal },\n\t\t);\n\t\tif (!confirmed || signal.aborted) return { kind: \"stay\" as const };\n\t\tif (!(await source.joinRoom(room, ctx, signal, { remember: true })) || signal.aborted) {\n\t\t\treturn { kind: \"stay\" as const };\n\t\t}\n\t\tawait source.openChat(ctx);\n\t\treturn { kind: \"close\" as const };\n\t};\n\tconst menu: MenuDefinition<ChatMenuState, Screen, Action> = {\n\t\tstart: \"main\",\n\t\tscreens: {\n\t\t\tmain: ({ state }) => mainScreen(state),\n\t\t\tinvite: ({ state }) => {\n\t\t\t\tconst room = state.pendingRoom ?? state.snapshot?.room;\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"review\",\n\t\t\t\t\ttitle: \"Private room invite\",\n\t\t\t\t\tlines: [\n\t\t\t\t\t\t\"Anyone with this bearer invite can join.\",\n\t\t\t\t\t\t\"After confirmation, choose whether to save it privately for restart restore.\",\n\t\t\t\t\t],\n\t\t\t\t\tcontent: room?.invite ?? \"Invite is unavailable.\",\n\t\t\t\t\tformat: { kind: \"text\" },\n\t\t\t\t\tviewportSize: \"adaptive\",\n\t\t\t\t\t...(state.pendingRoom\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tconfirm: {\n\t\t\t\t\t\t\t\t\tid: \"join-private\",\n\t\t\t\t\t\t\t\t\tlabel: \"Join private room\",\n\t\t\t\t\t\t\t\t\taction: \"joinPending\" as const,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: {}),\n\t\t\t\t\thint: \"back\",\n\t\t\t\t};\n\t\t\t},\n\t\t\tjoinInvite: () => ({\n\t\t\t\tkind: \"input\",\n\t\t\t\ttitle: \"Join with invite\",\n\t\t\t\tlines: [\n\t\t\t\t\t\"Paste a pichat:v1 or pichat:v2 invite. It grants access to the private room.\",\n\t\t\t\t\t\"You will choose Join and remember, Join once, or Cancel before networking starts.\",\n\t\t\t\t],\n\t\t\t\tplaceholder: \"pichat:v2:\u2026\",\n\t\t\t\taction: \"joinInvite\",\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\tjoinPublic: () => ({\n\t\t\t\tkind: \"input\",\n\t\t\t\ttitle: \"Join public room\",\n\t\t\t\tlines: [\"Use a lowercase room slug. Public rooms are guessable and open to anyone.\"],\n\t\t\t\tplaceholder: \"pi-dev\",\n\t\t\t\taction: \"joinPublic\",\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\tpublicRooms: ({ state }) => {\n\t\t\t\tconst rooms = state.directoryResult?.rooms ?? [];\n\t\t\t\tconst lines = state.directoryError\n\t\t\t\t\t? [\n\t\t\t\t\t\t\t`Discovery failed: ${sanitizeSingleLine(state.directoryError)}`,\n\t\t\t\t\t\t\t\"Retry or enter a known public room slug.\",\n\t\t\t\t\t\t]\n\t\t\t\t\t: rooms.length === 0\n\t\t\t\t\t\t? [\"No active public rooms were discovered. Counts are best-effort estimates.\"]\n\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\tstate.directoryResult?.partial\n\t\t\t\t\t\t\t\t\t? \"Estimated active participants \u00B7 partial discovered results.\"\n\t\t\t\t\t\t\t\t\t: \"Estimated active participants \u00B7 currently discovered results.\",\n\t\t\t\t\t\t\t\t\"Select a room to review the public-room warning before joining.\",\n\t\t\t\t\t\t\t];\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"choice\",\n\t\t\t\t\ttitle: \"Public rooms\",\n\t\t\t\t\tlines,\n\t\t\t\t\titems: [\n\t\t\t\t\t\t...rooms.map((room) => ({\n\t\t\t\t\t\t\tid: `room:${room.slug}`,\n\t\t\t\t\t\t\tlabel: `#${room.slug}`,\n\t\t\t\t\t\t\tdescription: `~${room.estimatedParticipants} active`,\n\t\t\t\t\t\t\tdetails: [\"Estimated from recent signed P2P directory presence.\"],\n\t\t\t\t\t\t})),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"route:refresh\",\n\t\t\t\t\t\t\tlabel: state.directoryError ? \"Retry discovery\" : \"Refresh discovery\",\n\t\t\t\t\t\t\tdescription: \"Query the P2P directory again\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"route:manual\",\n\t\t\t\t\t\t\tlabel: \"Enter room slug\",\n\t\t\t\t\t\t\tdescription: \"Join a known public room manually\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\taction: \"selectPublicRoom\",\n\t\t\t\t\tviewportSize: 10,\n\t\t\t\t\thint: \"back\",\n\t\t\t\t};\n\t\t\t},\n\t\t\tjoinAnother: () => ({\n\t\t\t\tkind: \"actions\",\n\t\t\t\ttitle: \"Join another room\",\n\t\t\t\tlines: [\"A successfully remembered join replaces the room restored at startup.\"],\n\t\t\t\titems: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"browse\",\n\t\t\t\t\t\tlabel: \"Browse public rooms\",\n\t\t\t\t\t\taction: \"browse\",\n\t\t\t\t\t\tbusyLabel: \"Discovering rooms\",\n\t\t\t\t\t},\n\t\t\t\t\t{ id: \"public\", label: \"Join public room\", to: \"joinPublic\" },\n\t\t\t\t\t{ id: \"invite\", label: \"Join with invite\", to: \"joinInvite\" },\n\t\t\t\t\t{ id: \"create\", label: \"Create private room\", action: \"createPrivate\" },\n\t\t\t\t],\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\tparticipants: ({ state }) => ({\n\t\t\t\tkind: \"choice\",\n\t\t\t\ttitle: \"Active participants\",\n\t\t\t\tlines: state.snapshot?.participants.length\n\t\t\t\t\t? [\"Select an origin to toggle local mute. Full public keys are shown in details.\"]\n\t\t\t\t\t: [\"No other active participants are currently discovered.\"],\n\t\t\t\titems:\n\t\t\t\t\tstate.snapshot?.participants.map((peer) => ({\n\t\t\t\t\t\tid: peer.publicKey,\n\t\t\t\t\t\tlabel: sanitizeSingleLine(peer.label),\n\t\t\t\t\t\tdescription: peer.muted ? \"Muted locally\" : \"Receiving messages\",\n\t\t\t\t\t\tdetails: [peer.publicKey],\n\t\t\t\t\t})) ?? [],\n\t\t\t\taction: \"toggleMute\",\n\t\t\t\tviewportSize: 10,\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\tsettings: ({ state }) => ({\n\t\t\t\tkind: \"actions\",\n\t\t\t\ttitle: \"Pi Chat settings\",\n\t\t\t\tlines: [\n\t\t\t\t\t`Nickname: ${sanitizeSingleLine(state.settings.nickname ?? \"not set\")}`,\n\t\t\t\t\t`Joined room display: ${state.settings.widgetMode ?? \"count\"}`,\n\t\t\t\t\t`Restart: ${restartDescription(state.settings)}`,\n\t\t\t\t\t`User settings \u00B7 ${sanitizeSingleLine(source.settingsPath)}`,\n\t\t\t\t],\n\t\t\t\titems: [\n\t\t\t\t\t{ id: \"nickname\", label: \"Change nickname\", to: \"changeNickname\" },\n\t\t\t\t\t{ id: \"widget\", label: \"Joined room display\", to: \"widget\" },\n\t\t\t\t\t{ id: \"reset\", label: \"Reset identity\u2026\", to: \"resetIdentity\" },\n\t\t\t\t],\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\tchangeNickname: () => ({\n\t\t\t\tkind: \"input\",\n\t\t\t\ttitle: \"Change nickname\",\n\t\t\t\tlines: [\"The immutable fingerprint remains attached to the new nickname.\"],\n\t\t\t\tplaceholder: \"Mika\",\n\t\t\t\taction: \"changeNickname\",\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\twidget: ({ state }) => ({\n\t\t\t\tkind: \"choice\",\n\t\t\t\ttitle: \"Joined room display\",\n\t\t\t\tlines: [\"Choose how much room content remains visible above the Pi editor.\"],\n\t\t\t\titems: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"dock\",\n\t\t\t\t\t\tlabel: \"Room dock\",\n\t\t\t\t\t\tdescription: \"Status, input target, and up to three recent messages\",\n\t\t\t\t\t},\n\t\t\t\t\t{ id: \"latest\", label: \"Latest message\", description: \"Show one recent message\" },\n\t\t\t\t\t{ id: \"count\", label: \"Status only\", description: \"Hide message text\" },\n\t\t\t\t\t{ id: \"off\", label: \"Hidden\", description: \"Show no persistent room widget\" },\n\t\t\t\t],\n\t\t\t\taction: \"setWidget\",\n\t\t\t\tcurrentItemId: state.settings.widgetMode ?? \"count\",\n\t\t\t\tinitialItemId: state.settings.widgetMode ?? \"count\",\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\tresetIdentity: () => {\n\t\t\t\tconst preview = source.getIdentityResetPreview();\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"review\",\n\t\t\t\t\ttitle: \"Reset Pi Chat identity?\",\n\t\t\t\t\tlines: [\n\t\t\t\t\t\t`Current: ${preview.current}`,\n\t\t\t\t\t\t`New: ${preview.next}`,\n\t\t\t\t\t\t\"Resetting changes your fingerprint, forgets startup restore, and leaves the room.\",\n\t\t\t\t\t],\n\t\t\t\t\tcontent: \"This cannot restore trust or blocked state associated with the old public key.\",\n\t\t\t\t\tformat: { kind: \"text\" },\n\t\t\t\t\tconfirm: { id: \"reset\", label: \"Reset identity\", action: \"resetIdentity\" },\n\t\t\t\t\thint: \"back\",\n\t\t\t\t};\n\t\t\t},\n\t\t\tleave: ({ state }) => {\n\t\t\t\tconst forgetsCurrent = state.settings.resume?.activeRoomId === state.snapshot?.room.id;\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"review\",\n\t\t\t\t\ttitle: forgetsCurrent ? \"Leave and forget room?\" : \"Leave room?\",\n\t\t\t\t\tlines: [\n\t\t\t\t\t\t`Room: ${sanitizeSingleLine(state.snapshot?.room.label ?? \"unknown\")}`,\n\t\t\t\t\t\tforgetsCurrent\n\t\t\t\t\t\t\t? \"Leaving disconnects peers, clears this transcript, and disables startup restore.\"\n\t\t\t\t\t\t\t: \"Leaving disconnects peers and clears this ephemeral transcript.\",\n\t\t\t\t\t],\n\t\t\t\t\tcontent: \"Messages already received by other peers cannot be withdrawn.\",\n\t\t\t\t\tformat: { kind: \"text\" },\n\t\t\t\t\tconfirm: {\n\t\t\t\t\t\tid: \"leave\",\n\t\t\t\t\t\tlabel: forgetsCurrent ? \"Leave and forget room\" : \"Leave room\",\n\t\t\t\t\t\taction: \"leave\",\n\t\t\t\t\t},\n\t\t\t\t\thint: \"back\",\n\t\t\t\t};\n\t\t\t},\n\t\t\tforget: ({ state }) => {\n\t\t\t\tconst room = rememberedRoom(state.settings);\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"review\",\n\t\t\t\t\ttitle: \"Forget saved room?\",\n\t\t\t\t\tlines: [\n\t\t\t\t\t\t`Room: ${sanitizeSingleLine(room?.label ?? \"unknown\")}`,\n\t\t\t\t\t\t\"Pi Chat will not reconnect to this room at startup.\",\n\t\t\t\t\t],\n\t\t\t\t\tcontent: \"This does not withdraw messages already received by peers.\",\n\t\t\t\t\tformat: { kind: \"text\" },\n\t\t\t\t\tconfirm: { id: \"forget\", label: \"Forget saved room\", action: \"forget\" },\n\t\t\t\t\thint: \"back\",\n\t\t\t\t};\n\t\t\t},\n\t\t\tstatus: ({ state }) => ({\n\t\t\t\tkind: \"detail\",\n\t\t\t\ttitle: \"Pi Chat status\",\n\t\t\t\tlines: state.snapshot\n\t\t\t\t\t? [\n\t\t\t\t\t\t\t`State: ${state.snapshot.state}`,\n\t\t\t\t\t\t\t`Room: ${sanitizeSingleLine(state.snapshot.room.label)}`,\n\t\t\t\t\t\t\t`Identity: ${sanitizeSingleLine(state.snapshot.localLabel)}`,\n\t\t\t\t\t\t\t`Active participants: ${state.snapshot.participants.length}`,\n\t\t\t\t\t\t\t`Direct neighbors: ${state.snapshot.directNeighbors}`,\n\t\t\t\t\t\t\t`Unread: ${state.snapshot.unread}`,\n\t\t\t\t\t\t\t`Restart: ${restartDescription(state.settings)}`,\n\t\t\t\t\t\t\t...(state.snapshot.lastError\n\t\t\t\t\t\t\t\t? [`Attention: ${sanitizeSingleLine(state.snapshot.lastError)}`]\n\t\t\t\t\t\t\t\t: []),\n\t\t\t\t\t\t]\n\t\t\t\t\t: [\n\t\t\t\t\t\t\t\"State: disconnected\",\n\t\t\t\t\t\t\t`Restart: ${restartDescription(state.settings)}`,\n\t\t\t\t\t\t\t...(state.restoreError\n\t\t\t\t\t\t\t\t? [`Attention: ${sanitizeSingleLine(state.restoreError)}`]\n\t\t\t\t\t\t\t\t: []),\n\t\t\t\t\t\t\t`Settings: ${sanitizeSingleLine(source.settingsPath)}`,\n\t\t\t\t\t\t],\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\thelp: () => ({\n\t\t\t\tkind: \"detail\",\n\t\t\t\ttitle: \"Pi Chat help\",\n\t\t\t\tlines: [\n\t\t\t\t\t\"Pi Chat is TUI-only.\",\n\t\t\t\t\t\"Chat stays outside Pi sessions, prompts, model context, and repository files.\",\n\t\t\t\t\t\"Private invites are bearer secrets. Public rooms are guessable.\",\n\t\t\t\t\t\"Noise encrypts direct streams, but peers and DHT infrastructure may observe network metadata.\",\n\t\t\t\t\t\"Public-room discovery and participant counts are approximate P2P observations.\",\n\t\t\t\t\t\"There is no offline delivery, global ordering, delivery receipt, or message withdrawal.\",\n\t\t\t\t],\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t},\n\t\tactions: {\n\t\t\tcreatePrivate: () => {\n\t\t\t\tpendingRoom = source.createPrivateRoom();\n\t\t\t\treturn { kind: \"to\", screen: \"invite\" };\n\t\t\t},\n\t\t\tjoinPending: async ({ ctx, signal }) => {\n\t\t\t\tif (!pendingRoom) return { kind: \"rejected\", error: new Error(\"Invite is unavailable\") };\n\t\t\t\tif (!(await source.joinRoom(pendingRoom, ctx, signal)) || signal.aborted) {\n\t\t\t\t\treturn { kind: \"stay\" };\n\t\t\t\t}\n\t\t\t\tawait source.openChat(ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tjoinInvite: async ({ ctx, signal, value }) => {\n\t\t\t\tlet room: RoomDescriptor;\n\t\t\t\ttry {\n\t\t\t\t\troom = parseInvite(value ?? \"\");\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn { kind: \"rejected\", error };\n\t\t\t\t}\n\t\t\t\tif (!(await source.joinRoom(room, ctx, signal)) || signal.aborted) return { kind: \"stay\" };\n\t\t\t\tawait source.openChat(ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tjoinPublic: ({ ctx, signal, value }) => joinPublic(value ?? \"\", ctx, signal),\n\t\t\tbrowse: ({ signal }) => browseRooms(signal),\n\t\t\tselectPublicRoom: async ({ ctx, signal, itemId }) => {\n\t\t\t\tif (itemId === \"route:refresh\") return browseRooms(signal);\n\t\t\t\tif (itemId === \"route:manual\") return { kind: \"to\", screen: \"joinPublic\" };\n\t\t\t\tif (!itemId.startsWith(\"room:\")) {\n\t\t\t\t\treturn { kind: \"rejected\", error: new Error(\"Public room selection is invalid\") };\n\t\t\t\t}\n\t\t\t\treturn joinPublic(itemId.slice(\"room:\".length), ctx, signal);\n\t\t\t},\n\t\t\tretry: async ({ ctx, signal }) => {\n\t\t\t\tawait source.retryRememberedRoom(ctx, signal);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tforget: async ({ signal }) => {\n\t\t\t\tawait source.forgetRememberedRoom(signal);\n\t\t\t\treturn { kind: \"to\", screen: \"main\" };\n\t\t\t},\n\t\t\topen: async ({ ctx }) => {\n\t\t\t\tawait source.openChat(ctx);\n\t\t\t\treturn { kind: \"close\" };\n\t\t\t},\n\t\t\tleave: async ({ signal }) => {\n\t\t\t\tawait source.leaveRoom(signal);\n\t\t\t\treturn { kind: \"to\", screen: \"main\" };\n\t\t\t},\n\t\t\ttoggleMute: ({ itemId }) => {\n\t\t\t\tconst muted = source.toggleMute(itemId);\n\t\t\t\treturn muted === undefined\n\t\t\t\t\t? { kind: \"rejected\", error: new Error(\"Peer is no longer connected\") }\n\t\t\t\t\t: { kind: \"to\", screen: \"participants\" };\n\t\t\t},\n\t\t\tchangeNickname: async ({ signal, value }) => {\n\t\t\t\tconst nickname = normalizeNickname(value);\n\t\t\t\tif (!nickname) return { kind: \"rejected\", error: new Error(\"Nickname is invalid\") };\n\t\t\t\tawait source.updateNickname(nickname, signal);\n\t\t\t\treturn { kind: \"to\", screen: \"settings\" };\n\t\t\t},\n\t\t\tsetWidget: async ({ signal, itemId }) => {\n\t\t\t\tif (itemId !== \"dock\" && itemId !== \"count\" && itemId !== \"latest\" && itemId !== \"off\") {\n\t\t\t\t\treturn { kind: \"rejected\", error: new Error(\"Widget mode is invalid\") };\n\t\t\t\t}\n\t\t\t\tawait source.updateWidgetMode(itemId, signal);\n\t\t\t\treturn { kind: \"to\", screen: \"settings\" };\n\t\t\t},\n\t\t\tresetIdentity: async ({ signal }) => {\n\t\t\t\tawait source.resetIdentity(signal);\n\t\t\t\treturn { kind: \"to\", screen: \"settings\" };\n\t\t\t},\n\t\t},\n\t};\n\treturn { menu, getState };\n}\n\nexport async function showChatMenu(\n\tctx: ExtensionCommandContext,\n\tsource: ChatMenuSource,\n\townership: { signal: AbortSignal; isCurrent: () => boolean },\n): Promise<void> {\n\tconst { runMenu } = await import(\"@narumitw/pi-tui-kit\");\n\tif (ownership.signal.aborted || !ownership.isCurrent()) return;\n\tconst controller = createChatMenu(source);\n\tawait runMenu(ctx, controller.menu, {\n\t\tgetState: controller.getState,\n\t\tsignal: ownership.signal,\n\t\tisCurrent: ownership.isCurrent,\n\t\tonError: (_ctx, error) => {\n\t\t\tif (ownership.isCurrent() && !ownership.signal.aborted) {\n\t\t\t\tctx.ui.notify(`Pi Chat failed: ${sanitizeSingleLine(safeError(error))}`, \"error\");\n\t\t\t}\n\t\t},\n\t});\n}\n\nfunction mainScreen(state: ChatMenuState) {\n\tconst remembered = rememberedRoom(state.settings);\n\tif (!state.snapshot || state.snapshot.state === \"disconnected\") {\n\t\tif (remembered) {\n\t\t\treturn {\n\t\t\t\tkind: \"actions\" as const,\n\t\t\t\ttitle: state.restoreError\n\t\t\t\t\t? `Pi Chat \u00B7 could not restore ${sanitizeSingleLine(remembered.label)}`\n\t\t\t\t\t: `Pi Chat \u00B7 ${sanitizeSingleLine(remembered.label)} remembered`,\n\t\t\t\tlines: [\n\t\t\t\t\tstate.restoreError\n\t\t\t\t\t\t? `Attention: ${sanitizeSingleLine(state.restoreError)}`\n\t\t\t\t\t\t: \"Disconnected. This room is configured to reconnect at startup.\",\n\t\t\t\t\t`Restart surface: ${state.settings.resume?.surface === \"chat\" ? \"open chat\" : \"Pi/LLM\"}`,\n\t\t\t\t],\n\t\t\t\titems: [\n\t\t\t\t\t{ id: \"retry\", label: `Retry ${remembered.label}`, action: \"retry\" as const },\n\t\t\t\t\t{ id: \"another\", label: \"Join another room\", to: \"joinAnother\" as const },\n\t\t\t\t\t{ id: \"forget\", label: `Forget ${remembered.label}\u2026`, to: \"forget\" as const },\n\t\t\t\t\t{ id: \"settings\", label: \"Settings\", to: \"settings\" as const },\n\t\t\t\t\t{ id: \"status\", label: \"Status\", to: \"status\" as const },\n\t\t\t\t\t{ id: \"help\", label: \"Help\", to: \"help\" as const },\n\t\t\t\t],\n\t\t\t\thint: \"close\" as const,\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tkind: \"actions\" as const,\n\t\t\ttitle: \"Pi Chat \u00B7 disconnected\",\n\t\t\tlines: [\"Peer-to-peer chat whose messages never enter model context.\"],\n\t\t\titems: [\n\t\t\t\t{\n\t\t\t\t\tid: \"browse\",\n\t\t\t\t\tlabel: \"Browse public rooms\",\n\t\t\t\t\taction: \"browse\" as const,\n\t\t\t\t\tbusyLabel: \"Discovering rooms\",\n\t\t\t\t},\n\t\t\t\t{ id: \"public\", label: \"Join public room\", to: \"joinPublic\" as const },\n\t\t\t\t{ id: \"invite\", label: \"Join with invite\", to: \"joinInvite\" as const },\n\t\t\t\t{ id: \"create\", label: \"Create private room\", action: \"createPrivate\" as const },\n\t\t\t\t{ id: \"settings\", label: \"Settings\", to: \"settings\" as const },\n\t\t\t\t{ id: \"status\", label: \"Status\", to: \"status\" as const },\n\t\t\t\t{ id: \"help\", label: \"Help\", to: \"help\" as const },\n\t\t\t],\n\t\t\thint: \"close\" as const,\n\t\t};\n\t}\n\tconst restoresCurrent = remembered?.id === state.snapshot.room.id;\n\treturn {\n\t\tkind: \"actions\" as const,\n\t\ttitle: `Pi Chat \u00B7 ${sanitizeSingleLine(state.snapshot.room.label)}`,\n\t\tlines: [\n\t\t\t`${state.snapshot.state} \u00B7 ${state.snapshot.participants.length} active \u00B7 ${state.snapshot.directNeighbors} direct neighbors \u00B7 ${state.snapshot.unread} unread`,\n\t\t\t`Current input: ${state.snapshot.composerOpen ? state.snapshot.room.label : \"Pi/LLM\"}`,\n\t\t\trestoresCurrent\n\t\t\t\t? `Restart: restore this room and ${state.settings.resume?.surface === \"chat\" ? \"open chat\" : \"stay in Pi/LLM\"}`\n\t\t\t\t: \"Restart: this room will not reconnect\",\n\t\t\tstate.snapshot.localLabel,\n\t\t],\n\t\titems: [\n\t\t\t{\n\t\t\t\tid: \"open\",\n\t\t\t\tlabel: `Open chat in ${sanitizeSingleLine(state.snapshot.room.label)}`,\n\t\t\t\taction: \"open\" as const,\n\t\t\t},\n\t\t\t{ id: \"participants\", label: \"Show active participants\", to: \"participants\" as const },\n\t\t\t...(state.snapshot.room.invite\n\t\t\t\t? [{ id: \"invite\", label: \"Show room invite\", to: \"invite\" as const }]\n\t\t\t\t: []),\n\t\t\t{ id: \"settings\", label: \"Settings\", to: \"settings\" as const },\n\t\t\t{ id: \"status\", label: \"Status\", to: \"status\" as const },\n\t\t\t{ id: \"help\", label: \"Help\", to: \"help\" as const },\n\t\t\t{\n\t\t\t\tid: \"leave\",\n\t\t\t\tlabel: restoresCurrent ? \"Leave and forget room\u2026\" : \"Leave room\u2026\",\n\t\t\t\tto: \"leave\" as const,\n\t\t\t},\n\t\t],\n\t\thint: \"close\" as const,\n\t};\n}\n\nfunction rememberedRoom(settings: ChatSettings): RoomDescriptor | undefined {\n\tconst resume = settings.resume;\n\tconst remembered = resume?.rooms.find(({ id }) => id === resume.activeRoomId);\n\tif (!remembered) return undefined;\n\ttry {\n\t\treturn descriptorFromRememberedRoom(remembered);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction restartDescription(settings: ChatSettings): string {\n\tconst room = rememberedRoom(settings);\n\tif (!room) return \"no room remembered\";\n\treturn `${room.label} \u00B7 ${settings.resume?.surface === \"chat\" ? \"open chat\" : \"stay in Pi/LLM\"}`;\n}\n\nfunction safeError(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AA8EO,SAAS,eAAe,QAAwB;AACtD,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,QAAM,WAAW,aAAqC;AAAA,IACrD,UAAU,OAAO,YAAY;AAAA,IAC7B,UAAU,OAAO,YAAY;AAAA,IAC7B;AAAA,IACA,GAAI,OAAO,gBAAgB,IAAI,EAAE,cAAc,OAAO,gBAAgB,EAAE,IAAI,CAAC;AAAA,IAC7E,GAAI,kBAAkB,EAAE,gBAAgB,IAAI,CAAC;AAAA,IAC7C,GAAI,iBAAiB,EAAE,eAAe,IAAI,CAAC;AAAA,EAC5C;AACA,QAAM,cAAc,OAAO,WAAwB;AAClD,QAAI;AACH,YAAM,SAAS,MAAM,OAAO,kBAAkB,MAAM;AACpD,UAAI,OAAO,QAAS,QAAO,EAAE,MAAM,OAAgB;AACnD,wBAAkB,EAAE,GAAG,QAAQ,OAAO,mBAAmB,OAAO,KAAK,EAAE;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I;AAAA,QACJ,OAAO,kBAAkB,gCAA2B;AAAA,QACpD,IAAI;AAAA,MACL;AAAA,IACD;AAAA,IACA,MAAM;AAAA,EACP;AACD;AAEA,SAAS,eAAe,UAAoD;AAC3E,QAAM,SAAS,SAAS;AACxB,QAAM,aAAa,QAAQ,MAAM,KAAK,CAAC,EAAE,GAAG,MAAM,OAAO,OAAO,YAAY;AAC5E,MAAI,CAAC,WAAY,QAAO;AACxB,MAAI;AACH,WAAO,6BAA6B,UAAU;AAAA,EAC/C,QAAQ;AACP,WAAO;AAAA,EACR;AACD;AAEA,SAAS,mBAAmB,UAAgC;AAC3D,QAAM,OAAO,eAAe,QAAQ;AACpC,MAAI,CAAC,KAAM,QAAO;AAClB,SAAO,GAAG,KAAK,KAAK,SAAM,SAAS,QAAQ,YAAY,SAAS,cAAc,gBAAgB;AAC/F;AAEA,SAAS,UAAU,OAAwB;AAC1C,SAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC7D;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/index.ts
CHANGED
|
@@ -546,7 +546,6 @@ function safeError(error) {
|
|
|
546
546
|
|
|
547
547
|
// src/pi-chat.ts
|
|
548
548
|
var CHAT_UI_KEY = "chat";
|
|
549
|
-
var EXPERIMENTAL_WARNING = "Pi Chat is experimental. Peer identity, networking, and interaction behavior may change.";
|
|
550
549
|
var USAGE = "Usage: /chat, /chat <pichat:v1-or-v2:invite>, or /chat #<public-slug>";
|
|
551
550
|
var PRIVATE_ROOM_OPTIONS = [
|
|
552
551
|
"Join and remember \u2014 Save the bearer invite privately and restore this room",
|
|
@@ -580,7 +579,7 @@ function createPiChatExtension(dependencies = {}) {
|
|
|
580
579
|
});
|
|
581
580
|
}),
|
|
582
581
|
updateSettings: dependencies.updateSettings ?? updateChatSettings,
|
|
583
|
-
loadChatMenu: cachedModuleLoader(dependencies.loadChatMenu ?? (() => import("./chunks/menu-
|
|
582
|
+
loadChatMenu: cachedModuleLoader(dependencies.loadChatMenu ?? (() => import("./chunks/menu-2KEDM6NJ.js"))),
|
|
584
583
|
loadChatView: cachedModuleLoader(dependencies.loadChatView ?? (() => import("./chunks/chat-view-EZ24L3LM.js"))),
|
|
585
584
|
loadChatWidget: cachedModuleLoader(
|
|
586
585
|
dependencies.loadChatWidget ?? (() => import("./chunks/widget-4OBABJDY.js"))
|
|
@@ -1086,7 +1085,7 @@ This pseudonymous fingerprint is not real-world identity verification.`,
|
|
|
1086
1085
|
};
|
|
1087
1086
|
};
|
|
1088
1087
|
pi.registerCommand("chat", {
|
|
1089
|
-
description: "Open
|
|
1088
|
+
description: "Open peer-to-peer developer chat",
|
|
1090
1089
|
handler: async (args, ctx) => {
|
|
1091
1090
|
if (ctx.mode !== "tui") throw new Error("Pi Chat requires Pi TUI mode.");
|
|
1092
1091
|
const owner = ctx.sessionManager;
|
|
@@ -1168,7 +1167,6 @@ This pseudonymous fingerprint is not real-world identity verification.`,
|
|
|
1168
1167
|
settings = {};
|
|
1169
1168
|
notifySafely(ctx, "Pi Chat settings are invalid; fix the file before saving.", "error");
|
|
1170
1169
|
}
|
|
1171
|
-
if (ctx.hasUI) notifySafely(ctx, EXPERIMENTAL_WARNING, "warning");
|
|
1172
1170
|
if (settings.resume && ctx.mode === "tui") {
|
|
1173
1171
|
void trackTask(restoreRememberedRoom(ctx, ownerGeneration));
|
|
1174
1172
|
}
|
package/dist/index.ts.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/pi-chat.ts", "../src/chat-session.ts"],
|
|
4
|
-
"sourcesContent": ["import { randomBytes as nodeRandomBytes } from \"node:crypto\";\nimport type {\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n} from \"@earendil-works/pi-coding-agent\";\nimport type { ChatSnapshot, ChatTransport } from \"./chat-session.js\";\nimport { ChatSession } from \"./chat-session.js\";\nimport type { PublicRoomDirectory } from \"./directory-network.js\";\nimport {\n\ttype ChatIdentity,\n\tcreateIdentity,\n\tderiveScopedIdentity,\n\tformatIdentityLabel,\n} from \"./identity.js\";\nimport type { ChatMenuSource, JoinRoomOptions } from \"./menu.js\";\nimport { type HyperswarmTransportOptions, MAX_DIRECT_NEIGHBORS } from \"./network-contract.js\";\nimport { createPrivateRoom, createPublicRoom, parseInvite, type RoomDescriptor } from \"./room.js\";\nimport {\n\tawaitChatSettingsWrites,\n\ttype ChatSettings,\n\tchatSettingsPath,\n\tdescriptorFromRememberedRoom,\n\treadChatSettings,\n\trememberedRoomFromDescriptor,\n\tupdateChatSettings as updateChatSettingsFile,\n\ttype WidgetMode,\n} from \"./settings.js\";\nimport { sanitizeSingleLine } from \"./text.js\";\n\nconst CHAT_UI_KEY = \"chat\";\nconst EXPERIMENTAL_WARNING =\n\t\"Pi Chat is experimental. Peer identity, networking, and interaction behavior may change.\";\nconst USAGE = \"Usage: /chat, /chat <pichat:v1-or-v2:invite>, or /chat #<public-slug>\";\nconst PRIVATE_ROOM_OPTIONS = [\n\t\"Join and remember \u2014 Save the bearer invite privately and restore this room\",\n\t\"Join once \u2014 Do not save the bearer invite\",\n\t\"Cancel\",\n] as const;\nconst DISPLAY_OPTIONS: ReadonlyArray<{ label: string; mode: WidgetMode }> = [\n\t{\n\t\tlabel: \"Room dock \u2014 Show up to three recent messages above the Pi editor\",\n\t\tmode: \"dock\",\n\t},\n\t{ label: \"Latest message \u2014 Show one recent message above the Pi editor\", mode: \"latest\" },\n\t{ label: \"Status only \u2014 Hide message text\", mode: \"count\" },\n\t{ label: \"Hidden \u2014 Show no persistent room widget\", mode: \"off\" },\n];\n\nexport interface PiChatDirectoryOptions {\n\tidentity: ChatIdentity;\n\tadvertisedSlug?: string;\n}\n\ntype Awaitable<Value> = Value | Promise<Value>;\ntype ChatMenuModule = Pick<typeof import(\"./menu.js\"), \"showChatMenu\">;\ntype ChatViewModule = Pick<typeof import(\"./chat-view.js\"), \"ChatView\">;\ntype ChatWidgetModule = Pick<typeof import(\"./widget.js\"), \"renderChatWidget\">;\n\nexport interface PiChatDependencies {\n\tsettingsPath: string;\n\trandomBytes(size: number): Buffer;\n\tcreateTransport(options: HyperswarmTransportOptions): Awaitable<ChatTransport>;\n\tcreateDirectory(options: PiChatDirectoryOptions): Awaitable<PublicRoomDirectory>;\n\tupdateSettings: typeof updateChatSettingsFile;\n\tloadChatMenu(): Promise<ChatMenuModule>;\n\tloadChatView(): Promise<ChatViewModule>;\n\tloadChatWidget(): Promise<ChatWidgetModule>;\n}\n\nexport function createPiChatExtension(\n\tdependencies: Partial<PiChatDependencies> = {},\n): (pi: ExtensionAPI) => void {\n\tconst loadNetwork = cachedModuleLoader(() => import(\"./network.js\"));\n\tconst loadDirectoryNetwork = cachedModuleLoader(() => import(\"./directory-network.js\"));\n\tconst deps: PiChatDependencies = {\n\t\tsettingsPath: dependencies.settingsPath ?? chatSettingsPath(),\n\t\trandomBytes: dependencies.randomBytes ?? nodeRandomBytes,\n\t\tcreateTransport:\n\t\t\tdependencies.createTransport ??\n\t\t\t(async (options) => {\n\t\t\t\tconst { HyperswarmTransport } = await loadNetwork();\n\t\t\t\treturn new HyperswarmTransport(options);\n\t\t\t}),\n\t\tcreateDirectory:\n\t\t\tdependencies.createDirectory ??\n\t\t\t(async (options) => {\n\t\t\t\tconst { HyperswarmDirectoryTransport, PublicRoomDirectorySession } =\n\t\t\t\t\tawait loadDirectoryNetwork();\n\t\t\t\treturn new PublicRoomDirectorySession({\n\t\t\t\t\t...options,\n\t\t\t\t\ttransport: new HyperswarmDirectoryTransport({ identity: options.identity }),\n\t\t\t\t});\n\t\t\t}),\n\t\tupdateSettings: dependencies.updateSettings ?? updateChatSettingsFile,\n\t\tloadChatMenu: cachedModuleLoader(dependencies.loadChatMenu ?? (() => import(\"./menu.js\"))),\n\t\tloadChatView: cachedModuleLoader(dependencies.loadChatView ?? (() => import(\"./chat-view.js\"))),\n\t\tloadChatWidget: cachedModuleLoader(\n\t\t\tdependencies.loadChatWidget ?? (() => import(\"./widget.js\")),\n\t\t),\n\t};\n\tconst updateChatSettings = deps.updateSettings;\n\n\treturn function piChatExtension(pi: ExtensionAPI): void {\n\t\tlet generation = 0;\n\t\tlet controller = new AbortController();\n\t\tlet activeSessionManager: unknown;\n\t\tlet activeContext: ExtensionContext | undefined;\n\t\tlet settings: ChatSettings = {};\n\t\tlet chatSession: ChatSession | undefined;\n\t\tlet roomDirectory: PublicRoomDirectory | undefined;\n\t\tlet latestSnapshot: ChatSnapshot | undefined;\n\t\tlet chatDraft = \"\";\n\t\tlet restoreError: string | undefined;\n\t\tlet restoringRoomId: string | undefined;\n\t\tlet joinOwner: { sessionManager: unknown; generation: number; token: symbol } | undefined;\n\t\tconst ownedTasks = new Set<Promise<unknown>>();\n\t\tlet renderChatWidget: ChatWidgetModule[\"renderChatWidget\"] | undefined;\n\t\tlet widgetRender: (() => void) | undefined;\n\t\tlet widgetInstalled = false;\n\n\t\tconst isCurrent = (owner: unknown, ownerGeneration: number) =>\n\t\t\tactiveSessionManager === owner &&\n\t\t\tgeneration === ownerGeneration &&\n\t\t\t!controller.signal.aborted;\n\n\t\tconst trackTask = <T>(task: Promise<T>): Promise<T> => {\n\t\t\townedTasks.add(task);\n\t\t\tvoid task.then(\n\t\t\t\t() => ownedTasks.delete(task),\n\t\t\t\t() => ownedTasks.delete(task),\n\t\t\t);\n\t\t\treturn task;\n\t\t};\n\n\t\tconst drainOwnedTasks = async (): Promise<void> => {\n\t\t\twhile (ownedTasks.size > 0) await Promise.allSettled([...ownedTasks]);\n\t\t};\n\n\t\tconst clearUi = (ctx: ExtensionContext, ownerGeneration = generation): void => {\n\t\t\ttry {\n\t\t\t\tctx.ui.setWidget(CHAT_UI_KEY, undefined);\n\t\t\t\tctx.ui.setStatus(CHAT_UI_KEY, undefined);\n\t\t\t} catch {\n\t\t\t\t// Session replacement may invalidate an old UI immediately.\n\t\t\t}\n\t\t\tif (ctx.sessionManager !== activeSessionManager || generation !== ownerGeneration) return;\n\t\t\trenderChatWidget = undefined;\n\t\t\twidgetRender = undefined;\n\t\t\twidgetInstalled = false;\n\t\t};\n\n\t\tconst updateUi = (ctx: ExtensionContext, snapshot?: ChatSnapshot): void => {\n\t\t\tif (ctx.sessionManager !== activeSessionManager) return;\n\t\t\tlatestSnapshot = snapshot;\n\t\t\ttry {\n\t\t\t\tctx.ui.setStatus(\n\t\t\t\t\tCHAT_UI_KEY,\n\t\t\t\t\tsnapshot?.state === \"connecting\"\n\t\t\t\t\t\t? restoringRoomId === snapshot.room.id\n\t\t\t\t\t\t\t? `chat: restoring ${sanitizeSingleLine(snapshot.room.label)}`\n\t\t\t\t\t\t\t: \"chat: joining\"\n\t\t\t\t\t\t: snapshot?.state === \"degraded\"\n\t\t\t\t\t\t\t? \"chat: reconnecting\"\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t);\n\t\t\t\tconst mode = settings.widgetMode ?? \"count\";\n\t\t\t\tif (\n\t\t\t\t\tctx.mode !== \"tui\" ||\n\t\t\t\t\t!snapshot ||\n\t\t\t\t\tsnapshot.state === \"disconnected\" ||\n\t\t\t\t\tmode === \"off\"\n\t\t\t\t) {\n\t\t\t\t\tctx.ui.setWidget(CHAT_UI_KEY, undefined);\n\t\t\t\t\twidgetInstalled = false;\n\t\t\t\t\twidgetRender = undefined;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst renderWidget = renderChatWidget;\n\t\t\t\tif (!renderWidget) return;\n\t\t\t\tif (!widgetInstalled) {\n\t\t\t\t\tctx.ui.setWidget(CHAT_UI_KEY, (tui, theme) => {\n\t\t\t\t\t\tconst requestRender = () => tui.requestRender();\n\t\t\t\t\t\twidgetRender = requestRender;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\trender: (width: number) =>\n\t\t\t\t\t\t\t\tlatestSnapshot\n\t\t\t\t\t\t\t\t\t? renderWidget(\n\t\t\t\t\t\t\t\t\t\t\tlatestSnapshot,\n\t\t\t\t\t\t\t\t\t\t\tsettings.widgetMode ?? \"count\",\n\t\t\t\t\t\t\t\t\t\t\twidth,\n\t\t\t\t\t\t\t\t\t\t\ttheme,\n\t\t\t\t\t\t\t\t\t\t\ttui.terminal.rows,\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t: [],\n\t\t\t\t\t\t\tinvalidate() {},\n\t\t\t\t\t\t\tdispose() {\n\t\t\t\t\t\t\t\tif (widgetRender === requestRender) widgetRender = undefined;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t});\n\t\t\t\t\twidgetInstalled = true;\n\t\t\t\t}\n\t\t\t\twidgetRender?.();\n\t\t\t} catch {\n\t\t\t\t// UI updates are best-effort after replacement.\n\t\t\t}\n\t\t};\n\n\t\tconst disconnectRoom = async (): Promise<void> => {\n\t\t\tconst owned = chatSession;\n\t\t\tconst ownedDirectory = roomDirectory;\n\t\t\tconst uiContext = activeContext;\n\t\t\tconst uiGeneration = generation;\n\t\t\tchatSession = undefined;\n\t\t\troomDirectory = undefined;\n\t\t\tlatestSnapshot = undefined;\n\t\t\tchatDraft = \"\";\n\t\t\tawait Promise.allSettled([owned?.leave(), ownedDirectory?.stop()]);\n\t\t\tif (uiContext) clearUi(uiContext, uiGeneration);\n\t\t};\n\n\t\tconst ensureIdentity = async (\n\t\t\tctx: ExtensionContext,\n\t\t\tsignal: AbortSignal,\n\t\t\towner: unknown,\n\t\t\townerGeneration: number,\n\t\t): Promise<ChatIdentity | undefined> => {\n\t\t\tlet nickname = settings.nickname;\n\t\t\tif (!nickname) {\n\t\t\t\tconst entered = await ctx.ui.input(\n\t\t\t\t\t\"Choose a Pi Chat nickname\",\n\t\t\t\t\t\"Visible to room peers; no OS or Git identity is used\",\n\t\t\t\t\t{ signal },\n\t\t\t\t);\n\t\t\t\tif (!isCurrent(owner, ownerGeneration) || signal.aborted || !entered) return undefined;\n\t\t\t\tnickname = entered;\n\t\t\t}\n\t\t\tlet seed = settings.identitySeed;\n\t\t\tlet widgetMode = settings.widgetMode;\n\t\t\tif (!seed) {\n\t\t\t\tconst candidate = createIdentity(deps.randomBytes(32));\n\t\t\t\tif (!widgetMode) {\n\t\t\t\t\tconst selected = await ctx.ui.select(\n\t\t\t\t\t\t\"Joined room display\",\n\t\t\t\t\t\tDISPLAY_OPTIONS.map(({ label }) => label),\n\t\t\t\t\t\t{ signal },\n\t\t\t\t\t);\n\t\t\t\t\tif (!selected || !isCurrent(owner, ownerGeneration) || signal.aborted) return undefined;\n\t\t\t\t\twidgetMode = DISPLAY_OPTIONS.find(({ label }) => label === selected)?.mode;\n\t\t\t\t\tif (!widgetMode) return undefined;\n\t\t\t\t}\n\t\t\t\tconst display =\n\t\t\t\t\tDISPLAY_OPTIONS.find(({ mode }) => mode === widgetMode)?.label ?? widgetMode;\n\t\t\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t\t\t\"Create Pi Chat identity?\",\n\t\t\t\t\t`${formatIdentityLabel(nickname, candidate.publicKey)}\\nDisplay: ${display}\\nThis pseudonymous fingerprint is not real-world identity verification.`,\n\t\t\t\t\t{ signal },\n\t\t\t\t);\n\t\t\t\tif (!confirmed || !isCurrent(owner, ownerGeneration) || signal.aborted) return undefined;\n\t\t\t\tseed = candidate.seed;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tnickname !== settings.nickname ||\n\t\t\t\tseed !== settings.identitySeed ||\n\t\t\t\twidgetMode !== settings.widgetMode\n\t\t\t) {\n\t\t\t\tconst updated = await updateChatSettings(\n\t\t\t\t\t{\n\t\t\t\t\t\tnickname,\n\t\t\t\t\t\tidentitySeed: seed,\n\t\t\t\t\t\t...(widgetMode ? { widgetMode } : {}),\n\t\t\t\t\t},\n\t\t\t\t\t{ settingsPath: deps.settingsPath, signal },\n\t\t\t\t);\n\t\t\t\tif (!isCurrent(owner, ownerGeneration)) return undefined;\n\t\t\t\tsettings = updated;\n\t\t\t}\n\t\t\treturn createIdentity(Buffer.from(seed, \"base64url\"));\n\t\t};\n\n\t\tconst startPublicRoomDirectory = (\n\t\t\troom: RoomDescriptor,\n\t\t\tidentity: ChatIdentity,\n\t\t\tsession: ChatSession,\n\t\t\tctx: ExtensionContext,\n\t\t\towner: unknown,\n\t\t\townerGeneration: number,\n\t\t): void => {\n\t\t\tif (room.kind !== \"public\" || !room.slug) return;\n\t\t\tvoid trackTask(\n\t\t\t\t(async () => {\n\t\t\t\t\tlet directory: PublicRoomDirectory | undefined;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tdirectory = await deps.createDirectory({\n\t\t\t\t\t\t\tidentity: deriveScopedIdentity(identity, `directory:#${room.slug}`),\n\t\t\t\t\t\t\tadvertisedSlug: room.slug,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t!isCurrent(owner, ownerGeneration) ||\n\t\t\t\t\t\t\tcontroller.signal.aborted ||\n\t\t\t\t\t\t\tchatSession !== session\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tawait directory.stop();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\troomDirectory = directory;\n\t\t\t\t\t\tawait directory.start(controller.signal);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconst ownsDirectory = !directory || roomDirectory === directory;\n\t\t\t\t\t\tif (directory && roomDirectory === directory) roomDirectory = undefined;\n\t\t\t\t\t\tif (directory) await Promise.allSettled([directory.stop()]);\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\townsDirectory &&\n\t\t\t\t\t\t\tisCurrent(owner, ownerGeneration) &&\n\t\t\t\t\t\t\tchatSession === session &&\n\t\t\t\t\t\t\tsession.snapshot().room.id === room.id\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tnotifySafely(\n\t\t\t\t\t\t\t\tctx,\n\t\t\t\t\t\t\t\t`Pi Chat public-room discovery is unavailable: ${sanitizeSingleLine(\n\t\t\t\t\t\t\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t\t\t\t\t\t)}. Chat remains connected.`,\n\t\t\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t})(),\n\t\t\t);\n\t\t};\n\n\t\tconst joinRoomOwned = async (\n\t\t\troom: RoomDescriptor,\n\t\t\tctx: ExtensionContext,\n\t\t\tsignal: AbortSignal,\n\t\t\toptions?: JoinRoomOptions,\n\t\t): Promise<boolean> => {\n\t\t\tif (chatSession && latestSnapshot?.state !== \"disconnected\") {\n\t\t\t\tthrow new Error(\"Leave the current Pi Chat room before joining another.\");\n\t\t\t}\n\t\t\tconst owner = ctx.sessionManager;\n\t\t\tconst ownerGeneration = generation;\n\t\t\tif (!isCurrent(owner, ownerGeneration)) throw new Error(\"Pi Chat session is stale.\");\n\t\t\tlet remember = options?.remember ?? false;\n\t\t\tif (room.kind === \"private\" && options === undefined) {\n\t\t\t\tconst selected = await ctx.ui.select(\n\t\t\t\t\t\"Private bearer invite \u2014 restore this room after restarting Pi?\",\n\t\t\t\t\t[...PRIVATE_ROOM_OPTIONS],\n\t\t\t\t\t{ signal },\n\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\t!selected ||\n\t\t\t\t\tselected === PRIVATE_ROOM_OPTIONS[2] ||\n\t\t\t\t\t!isCurrent(owner, ownerGeneration) ||\n\t\t\t\t\tsignal.aborted\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tremember = selected === PRIVATE_ROOM_OPTIONS[0];\n\t\t\t}\n\t\t\tconst identity = await ensureIdentity(ctx, signal, owner, ownerGeneration);\n\t\t\tif (!identity || !isCurrent(owner, ownerGeneration) || signal.aborted) return false;\n\t\t\tconst nickname = settings.nickname;\n\t\t\tif (!nickname) throw new Error(\"Pi Chat nickname is unavailable.\");\n\t\t\tconst widgetModule = await loadOwnedModule(\n\t\t\t\tdeps.loadChatWidget,\n\t\t\t\t() => isCurrent(owner, ownerGeneration) && !signal.aborted,\n\t\t\t);\n\t\t\tif (!widgetModule) return false;\n\t\t\tlet transport: ChatTransport;\n\t\t\ttry {\n\t\t\t\ttransport = await deps.createTransport({\n\t\t\t\t\troom,\n\t\t\t\t\tidentity,\n\t\t\t\t\tmaxPeers: MAX_DIRECT_NEIGHBORS,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tif (!isCurrent(owner, ownerGeneration) || signal.aborted) return false;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tif (!isCurrent(owner, ownerGeneration) || signal.aborted) {\n\t\t\t\tawait transport.stop();\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\trenderChatWidget = widgetModule.renderChatWidget;\n\t\t\tconst session = new ChatSession({\n\t\t\t\troom,\n\t\t\t\tidentity,\n\t\t\t\tnickname,\n\t\t\t\ttransport,\n\t\t\t\tonChange: (snapshot) => {\n\t\t\t\t\tif (chatSession !== session || !isCurrent(owner, ownerGeneration)) return;\n\t\t\t\t\tupdateUi(ctx, snapshot);\n\t\t\t\t},\n\t\t\t});\n\t\t\tchatSession = session;\n\t\t\tctx.ui.setStatus(CHAT_UI_KEY, \"chat: joining\");\n\t\t\ttry {\n\t\t\t\tawait session.start(AbortSignal.any([signal, controller.signal]));\n\t\t\t\tif (!isCurrent(owner, ownerGeneration) || chatSession !== session) {\n\t\t\t\t\tawait session.leave();\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tif (remember) {\n\t\t\t\t\tconst rememberedRoom = rememberedRoomFromDescriptor(room);\n\t\t\t\t\tconst next = await updateChatSettings(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tresume: {\n\t\t\t\t\t\t\t\trooms: [rememberedRoom],\n\t\t\t\t\t\t\t\tactiveRoomId: rememberedRoom.id,\n\t\t\t\t\t\t\t\tsurface: \"chat\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ settingsPath: deps.settingsPath, signal },\n\t\t\t\t\t);\n\t\t\t\t\tif (!isCurrent(owner, ownerGeneration) || chatSession !== session) {\n\t\t\t\t\t\tawait session.leave();\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tsettings = next;\n\t\t\t\t}\n\t\t\t\trestoreError = undefined;\n\t\t\t\tlatestSnapshot = session.snapshot();\n\t\t\t\tupdateUi(ctx, latestSnapshot);\n\t\t\t\tstartPublicRoomDirectory(room, identity, session, ctx, owner, ownerGeneration);\n\t\t\t\treturn true;\n\t\t\t} catch (error) {\n\t\t\t\tif (chatSession === session) chatSession = undefined;\n\t\t\t\tawait session.leave();\n\t\t\t\tclearUi(ctx, ownerGeneration);\n\t\t\t\tif (!signal.aborted && isCurrent(owner, ownerGeneration)) throw error;\n\t\t\t\treturn false;\n\t\t\t}\n\t\t};\n\n\t\tconst joinRoom: typeof joinRoomOwned = async (room, ctx, signal, options) => {\n\t\t\tconst existing = joinOwner;\n\t\t\tif (existing?.sessionManager === ctx.sessionManager && existing.generation === generation) {\n\t\t\t\tthrow new Error(\"A Pi Chat room join is already in progress.\");\n\t\t\t}\n\t\t\tconst token = Symbol(\"chat-join\");\n\t\t\tjoinOwner = { sessionManager: ctx.sessionManager, generation, token };\n\t\t\ttry {\n\t\t\t\treturn await joinRoomOwned(room, ctx, signal, options);\n\t\t\t} finally {\n\t\t\t\tif (joinOwner?.token === token) joinOwner = undefined;\n\t\t\t}\n\t\t};\n\n\t\tconst updateRememberedSurface = async (\n\t\t\tsurface: \"chat\" | \"pi\",\n\t\t\tctx: ExtensionContext,\n\t\t\towner: unknown,\n\t\t\townerGeneration: number,\n\t\t\tsession: ChatSession,\n\t\t): Promise<void> => {\n\t\t\tconst resume = settings.resume;\n\t\t\tif (\n\t\t\t\t!resume ||\n\t\t\t\tresume.activeRoomId !== session.snapshot().room.id ||\n\t\t\t\tresume.surface === surface\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst next = await updateChatSettings(\n\t\t\t\t\t{ resume: { ...resume, surface } },\n\t\t\t\t\t{ settingsPath: deps.settingsPath, signal: controller.signal },\n\t\t\t\t);\n\t\t\t\tif (isCurrent(owner, ownerGeneration) && chatSession === session) settings = next;\n\t\t\t} catch (error) {\n\t\t\t\tif (isCurrent(owner, ownerGeneration) && chatSession === session) {\n\t\t\t\t\tnotifySafely(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\t`Pi Chat could not save the restart view: ${sanitizeSingleLine(error instanceof Error ? error.message : String(error))}.`,\n\t\t\t\t\t\t\"error\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tconst openChat = async (ctx: ExtensionContext): Promise<void> => {\n\t\t\tconst session = chatSession;\n\t\t\tif (!session || session.snapshot().state === \"disconnected\") {\n\t\t\t\tthrow new Error(\"Join a Pi Chat room first.\");\n\t\t\t}\n\t\t\tconst owner = ctx.sessionManager;\n\t\t\tconst ownerGeneration = generation;\n\t\t\tconst ownerSignal = controller.signal;\n\t\t\tawait updateRememberedSurface(\"chat\", ctx, owner, ownerGeneration, session);\n\t\t\tif (!isCurrent(owner, ownerGeneration) || chatSession !== session) return;\n\t\t\tconst viewModule = await loadOwnedModule(\n\t\t\t\tdeps.loadChatView,\n\t\t\t\t() => isCurrent(owner, ownerGeneration) && chatSession === session,\n\t\t\t);\n\t\t\tif (!viewModule) return;\n\t\t\tconst { ChatView } = viewModule;\n\t\t\tawait ctx.ui.custom<void>(\n\t\t\t\t(tui, theme, _keybindings, done) =>\n\t\t\t\t\tnew ChatView({\n\t\t\t\t\t\ttui,\n\t\t\t\t\t\ttheme,\n\t\t\t\t\t\tgetSnapshot: () => session.snapshot(),\n\t\t\t\t\t\tsend: (text) => session.send(text),\n\t\t\t\t\t\tinitialDraft: chatDraft,\n\t\t\t\t\t\tonDraftChange: (text) => {\n\t\t\t\t\t\t\tif (isCurrent(owner, ownerGeneration) && chatSession === session) chatDraft = text;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tsetViewOpen: (open) => session.setViewOpen(open),\n\t\t\t\t\t\tsubscribe: (listener) => session.subscribe(listener),\n\t\t\t\t\t\tsignal: ownerSignal,\n\t\t\t\t\t\tonReturnToPi: () => {\n\t\t\t\t\t\t\tvoid trackTask(updateRememberedSurface(\"pi\", ctx, owner, ownerGeneration, session));\n\t\t\t\t\t\t},\n\t\t\t\t\t\tonClose: () => done(undefined),\n\t\t\t\t\t}),\n\t\t\t);\n\t\t\tif (isCurrent(owner, ownerGeneration) && chatSession === session)\n\t\t\t\tupdateUi(ctx, session.snapshot());\n\t\t};\n\n\t\tconst restoreRememberedRoom = async (\n\t\t\tctx: ExtensionContext,\n\t\t\townerGeneration: number,\n\t\t\tsignal: AbortSignal = controller.signal,\n\t\t): Promise<void> => {\n\t\t\tconst resume = settings.resume;\n\t\t\tif (!resume || !settings.nickname || !settings.identitySeed || ctx.mode !== \"tui\") return;\n\t\t\tconst remembered = resume.rooms.find(({ id }) => id === resume.activeRoomId);\n\t\t\tif (!remembered || !isCurrent(ctx.sessionManager, ownerGeneration)) return;\n\t\t\tlet room: RoomDescriptor;\n\t\t\ttry {\n\t\t\t\troom = descriptorFromRememberedRoom(remembered);\n\t\t\t} catch {\n\t\t\t\tnotifySafely(ctx, \"Pi Chat could not restore the saved room; fix pi-chat.json.\", \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\trestoreError = undefined;\n\t\t\trestoringRoomId = room.id;\n\t\t\ttry {\n\t\t\t\tctx.ui.setStatus(CHAT_UI_KEY, `chat: restoring ${sanitizeSingleLine(room.label)}`);\n\t\t\t\tconst joined = await joinRoom(room, ctx, signal, { remember: false });\n\t\t\t\tif (!joined || signal.aborted || !isCurrent(ctx.sessionManager, ownerGeneration)) return;\n\t\t\t\tif (resume.surface === \"chat\") await openChat(ctx);\n\t\t\t} catch (error) {\n\t\t\t\tif (isCurrent(ctx.sessionManager, ownerGeneration)) {\n\t\t\t\t\trestoreError = sanitizeSingleLine(error instanceof Error ? error.message : String(error));\n\t\t\t\t\tctx.ui.setStatus(CHAT_UI_KEY, \"chat: restore failed\");\n\t\t\t\t\tnotifySafely(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\t`Pi Chat could not restore ${sanitizeSingleLine(room.label)}: ${restoreError}. Use /chat to retry or forget it.`,\n\t\t\t\t\t\t\"error\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tif (restoringRoomId === room.id) restoringRoomId = undefined;\n\t\t\t}\n\t\t};\n\n\t\tconst menuSource = (ctx: ExtensionCommandContext): ChatMenuSource => {\n\t\t\tconst resetIdentity = createIdentity(deps.randomBytes(32));\n\t\t\tconst owner = ctx.sessionManager;\n\t\t\tconst ownerGeneration = generation;\n\t\t\tconst ownsMenu = () => isCurrent(owner, ownerGeneration);\n\t\t\treturn {\n\t\t\t\tsettingsPath: deps.settingsPath,\n\t\t\t\tgetSettings: () => settings,\n\t\t\t\tgetSnapshot: () => chatSession?.snapshot(),\n\t\t\t\tgetRestoreError: () => restoreError,\n\t\t\t\tcreatePrivateRoom: () => createPrivateRoom(deps.randomBytes(32)),\n\t\t\t\tbrowsePublicRooms: async (signal) => {\n\t\t\t\t\tif (!ownsMenu()) throw new Error(\"Pi Chat session is stale.\");\n\t\t\t\t\tconst activeDirectory = roomDirectory;\n\t\t\t\t\tconst directory =\n\t\t\t\t\t\tactiveDirectory ??\n\t\t\t\t\t\t(await deps.createDirectory({ identity: createIdentity(deps.randomBytes(32)) }));\n\t\t\t\t\tconst temporary = activeDirectory ? undefined : directory;\n\t\t\t\t\tconst browseSignal = AbortSignal.any([signal, controller.signal]);\n\t\t\t\t\tif (!ownsMenu() || browseSignal.aborted) {\n\t\t\t\t\t\tif (temporary) await temporary.stop();\n\t\t\t\t\t\tthrow browseSignal.reason ?? new DOMException(\"Aborted\", \"AbortError\");\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = await directory.browse(browseSignal);\n\t\t\t\t\t\tif (!ownsMenu() || browseSignal.aborted) {\n\t\t\t\t\t\t\tthrow browseSignal.reason ?? new DOMException(\"Aborted\", \"AbortError\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tif (temporary) await temporary.stop();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tjoinRoom,\n\t\t\t\topenChat: async (commandCtx) => {\n\t\t\t\t\tif (ownsMenu()) await openChat(commandCtx);\n\t\t\t\t},\n\t\t\t\tretryRememberedRoom: async (commandCtx, signal) => {\n\t\t\t\t\tif (!ownsMenu() || signal.aborted) return;\n\t\t\t\t\tawait restoreRememberedRoom(\n\t\t\t\t\t\tcommandCtx,\n\t\t\t\t\t\townerGeneration,\n\t\t\t\t\t\tAbortSignal.any([signal, controller.signal]),\n\t\t\t\t\t);\n\t\t\t\t\tif (restoreError) throw new Error(restoreError);\n\t\t\t\t},\n\t\t\t\tforgetRememberedRoom: async (signal) => {\n\t\t\t\t\tif (!ownsMenu()) return;\n\t\t\t\t\tif (settings.resume) {\n\t\t\t\t\t\tconst next = await updateChatSettings(\n\t\t\t\t\t\t\t{ resume: null },\n\t\t\t\t\t\t\t{ settingsPath: deps.settingsPath, signal },\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (!ownsMenu()) return;\n\t\t\t\t\t\tsettings = next;\n\t\t\t\t\t}\n\t\t\t\t\trestoreError = undefined;\n\t\t\t\t\tclearUi(ctx);\n\t\t\t\t},\n\t\t\t\tleaveRoom: async (signal) => {\n\t\t\t\t\tif (!ownsMenu()) return;\n\t\t\t\t\tconst currentRoomId = chatSession?.snapshot().room.id;\n\t\t\t\t\tif (settings.resume && settings.resume.activeRoomId === currentRoomId) {\n\t\t\t\t\t\tconst next = await updateChatSettings(\n\t\t\t\t\t\t\t{ resume: null },\n\t\t\t\t\t\t\t{ settingsPath: deps.settingsPath, signal },\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (!ownsMenu()) return;\n\t\t\t\t\t\tsettings = next;\n\t\t\t\t\t}\n\t\t\t\t\trestoreError = undefined;\n\t\t\t\t\tawait disconnectRoom();\n\t\t\t\t},\n\t\t\t\ttoggleMute(publicKey) {\n\t\t\t\t\tif (!ownsMenu() || !/^[0-9a-f]{64}$/u.test(publicKey)) return undefined;\n\t\t\t\t\tconst muted = chatSession?.toggleMute(Buffer.from(publicKey, \"hex\"));\n\t\t\t\t\tif (chatSession) updateUi(ctx, chatSession.snapshot());\n\t\t\t\t\treturn muted;\n\t\t\t\t},\n\t\t\t\tasync updateNickname(value, signal) {\n\t\t\t\t\tconst previous = settings;\n\t\t\t\t\tconst next = await updateChatSettings(\n\t\t\t\t\t\t{ nickname: value },\n\t\t\t\t\t\t{ settingsPath: deps.settingsPath, signal },\n\t\t\t\t\t);\n\t\t\t\t\tif (!ownsMenu()) return;\n\t\t\t\t\tsettings = next;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tchatSession?.updateNickname(value);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tsettings = previous;\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\t\t\t\t\tif (chatSession) updateUi(ctx, chatSession.snapshot());\n\t\t\t\t},\n\t\t\t\tasync updateWidgetMode(value, signal) {\n\t\t\t\t\tconst next = await updateChatSettings(\n\t\t\t\t\t\t{ widgetMode: value },\n\t\t\t\t\t\t{ settingsPath: deps.settingsPath, signal },\n\t\t\t\t\t);\n\t\t\t\t\tif (!ownsMenu()) return;\n\t\t\t\t\tsettings = next;\n\t\t\t\t\tupdateUi(ctx, chatSession?.snapshot());\n\t\t\t\t},\n\t\t\t\tgetIdentityResetPreview: () => {\n\t\t\t\t\tconst current = settings.identitySeed\n\t\t\t\t\t\t? formatIdentityLabel(\n\t\t\t\t\t\t\t\tsettings.nickname ?? \"anonymous\",\n\t\t\t\t\t\t\t\tcreateIdentity(Buffer.from(settings.identitySeed, \"base64url\")).publicKey,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: \"not created\";\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcurrent,\n\t\t\t\t\t\tnext: formatIdentityLabel(settings.nickname ?? \"anonymous\", resetIdentity.publicKey),\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\tasync resetIdentity(signal) {\n\t\t\t\t\tconst next = await updateChatSettings(\n\t\t\t\t\t\t{ identitySeed: resetIdentity.seed, resume: null },\n\t\t\t\t\t\t{ settingsPath: deps.settingsPath, signal },\n\t\t\t\t\t);\n\t\t\t\t\tif (!ownsMenu()) return;\n\t\t\t\t\tsettings = next;\n\t\t\t\t\tawait disconnectRoom();\n\t\t\t\t},\n\t\t\t};\n\t\t};\n\n\t\tpi.registerCommand(\"chat\", {\n\t\t\tdescription: \"Open experimental peer-to-peer developer chat\",\n\t\t\thandler: async (args, ctx) => {\n\t\t\t\tif (ctx.mode !== \"tui\") throw new Error(\"Pi Chat requires Pi TUI mode.\");\n\t\t\t\tconst owner = ctx.sessionManager;\n\t\t\t\tconst ownerGeneration = generation;\n\t\t\t\tif (!isCurrent(owner, ownerGeneration)) throw new Error(\"Pi Chat session is stale.\");\n\t\t\t\tconst input = args.trim();\n\t\t\t\tif (!input) {\n\t\t\t\t\tconst menuModule = await loadOwnedModule(deps.loadChatMenu, () =>\n\t\t\t\t\t\tisCurrent(owner, ownerGeneration),\n\t\t\t\t\t);\n\t\t\t\t\tif (!menuModule) return;\n\t\t\t\t\tconst { showChatMenu } = menuModule;\n\t\t\t\t\tawait showChatMenu(ctx, menuSource(ctx), {\n\t\t\t\t\t\tsignal: controller.signal,\n\t\t\t\t\t\tisCurrent: () => isCurrent(owner, ownerGeneration),\n\t\t\t\t\t});\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (/\\s/u.test(input)) {\n\t\t\t\t\tnotifySafely(ctx, USAGE, \"warning\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlet room: RoomDescriptor;\n\t\t\t\tlet openAfterJoin = false;\n\t\t\t\tif (input.startsWith(\"pichat:\")) {\n\t\t\t\t\topenAfterJoin = true;\n\t\t\t\t\ttry {\n\t\t\t\t\t\troom = parseInvite(input);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tnotifySafely(ctx, USAGE, \"warning\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t} else if (input.startsWith(\"#\")) {\n\t\t\t\t\topenAfterJoin = true;\n\t\t\t\t\ttry {\n\t\t\t\t\t\troom = createPublicRoom(input.slice(1));\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tnotifySafely(ctx, USAGE, \"warning\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t\t\t\t\"Join public room?\",\n\t\t\t\t\t\t\"Anyone can join or record it. DHT and direct peers may observe network metadata.\",\n\t\t\t\t\t\t{ signal: controller.signal },\n\t\t\t\t\t);\n\t\t\t\t\tif (!confirmed || !isCurrent(owner, ownerGeneration)) return;\n\t\t\t\t} else {\n\t\t\t\t\tnotifySafely(ctx, USAGE, \"warning\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst joined = await joinRoom(\n\t\t\t\t\troom,\n\t\t\t\t\tctx,\n\t\t\t\t\tcontroller.signal,\n\t\t\t\t\troom.kind === \"public\" ? { remember: true } : undefined,\n\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\tjoined &&\n\t\t\t\t\topenAfterJoin &&\n\t\t\t\t\t!controller.signal.aborted &&\n\t\t\t\t\tisCurrent(owner, ownerGeneration)\n\t\t\t\t) {\n\t\t\t\t\tawait openChat(ctx);\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\n\t\tpi.on(\"session_start\", async (_event, ctx) => {\n\t\t\tcontroller.abort(new DOMException(\"Pi Chat session replaced\", \"AbortError\"));\n\t\t\tawait disconnectRoom();\n\t\t\tawait drainOwnedTasks();\n\t\t\tcontroller = new AbortController();\n\t\t\tgeneration += 1;\n\t\t\tactiveSessionManager = ctx.sessionManager;\n\t\t\tactiveContext = ctx;\n\t\t\trestoreError = undefined;\n\t\t\tclearUi(ctx);\n\t\t\tconst ownerGeneration = generation;\n\t\t\tconst loaded = await readChatSettings(deps.settingsPath);\n\t\t\tif (generation !== ownerGeneration || activeSessionManager !== ctx.sessionManager) return;\n\t\t\tif (loaded.kind === \"loaded\") settings = loaded.settings;\n\t\t\telse if (loaded.kind === \"missing\") settings = {};\n\t\t\telse {\n\t\t\t\tsettings = {};\n\t\t\t\tnotifySafely(ctx, \"Pi Chat settings are invalid; fix the file before saving.\", \"error\");\n\t\t\t}\n\t\t\tif (ctx.hasUI) notifySafely(ctx, EXPERIMENTAL_WARNING, \"warning\");\n\t\t\tif (settings.resume && ctx.mode === \"tui\") {\n\t\t\t\tvoid trackTask(restoreRememberedRoom(ctx, ownerGeneration));\n\t\t\t}\n\t\t});\n\n\t\tpi.on(\"session_shutdown\", async (_event, ctx) => {\n\t\t\tconst owner = ctx.sessionManager;\n\t\t\tif (owner !== activeSessionManager) return;\n\t\t\tcontroller.abort(new DOMException(\"Pi Chat session shut down\", \"AbortError\"));\n\t\t\tconst shutdownGeneration = ++generation;\n\t\t\tawait disconnectRoom();\n\t\t\tawait drainOwnedTasks();\n\t\t\tawait awaitChatSettingsWrites(deps.settingsPath);\n\t\t\tif (activeSessionManager !== owner || generation !== shutdownGeneration) return;\n\t\t\tclearUi(ctx);\n\t\t\tactiveSessionManager = undefined;\n\t\t\tactiveContext = undefined;\n\t\t});\n\t};\n}\n\nfunction notifySafely(\n\tctx: ExtensionContext,\n\tmessage: string,\n\tlevel: \"info\" | \"warning\" | \"error\",\n): void {\n\ttry {\n\t\tctx.ui.notify(sanitizeSingleLine(message), level);\n\t} catch {\n\t\t// Stale UI errors must not escape lifecycle cleanup.\n\t}\n}\n\nasync function loadOwnedModule<Module>(\n\tload: () => Promise<Module>,\n\tisCurrent: () => boolean,\n): Promise<Module | undefined> {\n\ttry {\n\t\tconst module = await load();\n\t\treturn isCurrent() ? module : undefined;\n\t} catch (error) {\n\t\tif (!isCurrent()) return undefined;\n\t\tthrow error;\n\t}\n}\n\nfunction cachedModuleLoader<Module>(load: () => Promise<Module>): () => Promise<Module> {\n\tlet pending: Promise<Module> | undefined;\n\treturn () => {\n\t\tif (!pending) {\n\t\t\tpending = load().catch((error) => {\n\t\t\t\tpending = undefined;\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t}\n\t\treturn pending;\n\t};\n}\n\nexport default createPiChatExtension();\n", "import { randomBytes, randomUUID } from \"node:crypto\";\nimport type { ChatIdentity } from \"./identity.js\";\nimport { formatIdentityLabel, normalizeNickname, uniqueIdentityTags } from \"./identity.js\";\nimport {\n\tcreateChatEvent,\n\tcreateGossipMessage,\n\tcreateHello,\n\tcreatePresenceEvent,\n\ttype GossipMessage,\n\tMAX_EVENT_AGE_MS,\n\tPeerRateLimiter,\n\ttype PresenceEvent,\n\ttype ProtocolMessage,\n\ttype RoomDescriptor,\n\ttype RoomEvent,\n\tverifyHello,\n\tverifyRoomEvent,\n} from \"./protocol.js\";\n\nconst MAX_TRANSCRIPT = 256;\nconst MAX_SEEN_MESSAGES = 8_192;\nconst SEEN_MESSAGE_TTL_MS = 10 * 60_000;\nconst MAX_PROTOCOL_VIOLATIONS = 3;\nconst MAX_PARTICIPANTS = 256;\nconst PARTICIPANT_TTL_MS = 90_000;\nconst PRESENCE_HEARTBEAT_MS = 30_000;\nconst MAX_ORIGIN_LIMITERS = 512;\n\nexport interface TransportPeer {\n\tpublicKey: Buffer;\n\tsend(message: ProtocolMessage): void;\n\tclose(): void;\n}\n\nexport interface ChatTransportListener {\n\tonPeer(peer: TransportPeer): void;\n\tonMessage(peer: TransportPeer, message: ProtocolMessage): void;\n\tonDisconnect(peer: TransportPeer): void;\n\tonError(error: Error): void;\n}\n\nexport interface ChatTransport {\n\tstart(listener: ChatTransportListener, signal?: AbortSignal): Promise<void>;\n\tstop(): Promise<void>;\n}\n\nexport interface TranscriptEntry {\n\tid: string;\n\tauthor: \"local\" | \"remote\";\n\tlabel: string;\n\tpublicKey: string;\n\ttext: string;\n\tsentAt: number;\n\tdelivery?: \"relayed\" | \"not-relayed\";\n\trelayedTo?: number;\n}\n\nexport interface ParticipantSnapshot {\n\tpublicKey: string;\n\tlabel: string;\n\tnickname: string;\n\tmuted: boolean;\n}\n\nexport interface ChatSnapshot {\n\tstate: \"connecting\" | \"connected\" | \"degraded\" | \"disconnected\";\n\troom: RoomDescriptor;\n\tlocalLabel: string;\n\tparticipants: ParticipantSnapshot[];\n\tdirectNeighbors: number;\n\tparticipantCatalogFull: boolean;\n\ttranscript: TranscriptEntry[];\n\tunread: number;\n\tcomposerOpen: boolean;\n\tlastError?: string;\n}\n\nexport interface ChatSessionOptions {\n\troom: RoomDescriptor;\n\tidentity: ChatIdentity;\n\tnickname: string;\n\ttransport: ChatTransport;\n\tnow?: () => number;\n\tonChange?: (snapshot: ChatSnapshot) => void;\n}\n\ninterface PeerState {\n\tpeer: TransportPeer;\n\tauthenticated: boolean;\n\tnickname?: string;\n\tviolations: number;\n\tlimiter: PeerRateLimiter;\n}\n\ninterface ParticipantState {\n\tpublicKey: Buffer;\n\tnickname: string;\n\tmuted: boolean;\n\tlastSeen: number;\n}\n\ninterface OriginLimiterState {\n\tlimiter: PeerRateLimiter;\n\tlastSeen: number;\n}\n\ninterface ParticipantVersionState {\n\tissuedAt: number;\n\tid: string;\n}\n\nexport class ChatSession {\n\tprivate readonly room: RoomDescriptor;\n\tprivate readonly identity: ChatIdentity;\n\tprivate nickname: string;\n\tprivate readonly transport: ChatTransport;\n\tprivate readonly now: () => number;\n\tprivate readonly onChange?: (snapshot: ChatSnapshot) => void;\n\tprivate readonly peers = new Map<string, PeerState>();\n\tprivate readonly participants = new Map<string, ParticipantState>();\n\tprivate readonly mutedOrigins = new Set<string>();\n\tprivate readonly transcript: TranscriptEntry[] = [];\n\tprivate readonly seen = new Map<string, number>();\n\tprivate readonly seenOrder: Array<{ key: string; expiresAt: number }> = [];\n\tprivate readonly originLimiters = new Map<string, OriginLimiterState>();\n\tprivate readonly participantVersions = new Map<string, ParticipantVersionState>();\n\tprivate readonly listeners = new Set<(snapshot: ChatSnapshot) => void>();\n\tprivate state: ChatSnapshot[\"state\"] = \"disconnected\";\n\tprivate unread = 0;\n\tprivate viewOpen = false;\n\tprivate lastError: string | undefined;\n\tprivate generation = 0;\n\tprivate leavePromise: Promise<void> | undefined;\n\tprivate heartbeatTimer: NodeJS.Timeout | undefined;\n\tprivate currentPresence: PresenceEvent | undefined;\n\tprivate participantCatalogFull = false;\n\n\tconstructor(options: ChatSessionOptions) {\n\t\tconst nickname = normalizeNickname(options.nickname);\n\t\tif (!nickname) throw new Error(\"Pi Chat nickname is invalid.\");\n\t\tthis.room = options.room;\n\t\tthis.identity = options.identity;\n\t\tthis.nickname = nickname;\n\t\tthis.transport = options.transport;\n\t\tthis.now = options.now ?? Date.now;\n\t\tthis.onChange = options.onChange;\n\t}\n\n\tasync start(signal?: AbortSignal): Promise<void> {\n\t\tif (this.state !== \"disconnected\" || this.leavePromise) {\n\t\t\tthrow new Error(\"Pi Chat session has already started.\");\n\t\t}\n\t\tconst owner = ++this.generation;\n\t\tthis.state = \"connecting\";\n\t\tthis.emit();\n\t\ttry {\n\t\t\tawait this.transport.start(\n\t\t\t\t{\n\t\t\t\t\tonPeer: (peer) => this.onPeer(owner, peer),\n\t\t\t\t\tonMessage: (peer, message) => this.onMessage(owner, peer, message),\n\t\t\t\t\tonDisconnect: (peer) => this.onDisconnect(owner, peer),\n\t\t\t\t\tonError: (error) => this.onError(owner, error),\n\t\t\t\t},\n\t\t\t\tsignal,\n\t\t\t);\n\t\t\tsignal?.throwIfAborted();\n\t\t\tif (owner !== this.generation) return;\n\t\t\tthis.state = \"connected\";\n\t\t\tthis.startHeartbeat(owner);\n\t\t\tthis.emit();\n\t\t} catch (error) {\n\t\t\tif (owner === this.generation) {\n\t\t\t\tthis.state = \"disconnected\";\n\t\t\t\tthis.lastError = safeError(error);\n\t\t\t\tthis.emit();\n\t\t\t}\n\t\t\tawait this.transport.stop().catch(() => undefined);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tsend(text: string): { id: string; relayedTo: number } {\n\t\tif (this.state !== \"connected\" && this.state !== \"degraded\") {\n\t\t\tthrow new Error(\"Pi Chat is not connected.\");\n\t\t}\n\t\tconst id = randomUUID();\n\t\tconst event = createChatEvent(this.room, this.identity, this.nickname, text, this.now(), id);\n\t\tthis.remember(eventKey(event));\n\t\tconst relayedTo = this.broadcast(createGossipMessage(event));\n\t\tthis.pushTranscript({\n\t\t\tid,\n\t\t\tauthor: \"local\",\n\t\t\tlabel: formatIdentityLabel(this.nickname, this.identity.publicKey),\n\t\t\tpublicKey: this.identity.publicKey.toString(\"hex\"),\n\t\t\ttext,\n\t\t\tsentAt: event.issuedAt,\n\t\t\tdelivery: relayedTo > 0 ? \"relayed\" : \"not-relayed\",\n\t\t\trelayedTo,\n\t\t});\n\t\tthis.emit();\n\t\treturn { id, relayedTo };\n\t}\n\n\tupdateNickname(value: string): void {\n\t\tconst nickname = normalizeNickname(value);\n\t\tif (!nickname) throw new Error(\"Pi Chat nickname is invalid.\");\n\t\tthis.nickname = nickname;\n\t\tthis.publishPresence(\"online\");\n\t\tthis.emit();\n\t}\n\n\tmute(publicKey: Uint8Array): void {\n\t\tconst id = keyId(publicKey);\n\t\tif (!this.participants.has(id)) return;\n\t\tthis.mutedOrigins.add(id);\n\t\tconst participant = this.participants.get(id);\n\t\tif (participant) participant.muted = true;\n\t\tthis.emit();\n\t}\n\n\ttoggleMute(publicKey: Uint8Array): boolean | undefined {\n\t\tconst id = keyId(publicKey);\n\t\tconst participant = this.participants.get(id);\n\t\tif (!participant) return undefined;\n\t\tif (this.mutedOrigins.has(id)) {\n\t\t\tthis.mutedOrigins.delete(id);\n\t\t\tparticipant.muted = false;\n\t\t} else {\n\t\t\tthis.mutedOrigins.add(id);\n\t\t\tparticipant.muted = true;\n\t\t}\n\t\tthis.emit();\n\t\treturn participant.muted;\n\t}\n\n\tsubscribe(listener: (snapshot: ChatSnapshot) => void): () => void {\n\t\tthis.listeners.add(listener);\n\t\treturn () => this.listeners.delete(listener);\n\t}\n\n\tsetViewOpen(open: boolean): void {\n\t\tif (this.viewOpen === open) return;\n\t\tthis.viewOpen = open;\n\t\tif (open) this.unread = 0;\n\t\tthis.emit();\n\t}\n\n\tleave(): Promise<void> {\n\t\tif (this.leavePromise) return this.leavePromise;\n\t\tthis.leavePromise = this.leaveOwned();\n\t\treturn this.leavePromise;\n\t}\n\n\tsnapshot(): ChatSnapshot {\n\t\tthis.pruneParticipants();\n\t\tconst active = [...this.participants.entries()];\n\t\tconst tags = uniqueIdentityTags([\n\t\t\tthis.identity.publicKey,\n\t\t\t...active.map(([, value]) => value.publicKey),\n\t\t]);\n\t\tconst localKey = this.identity.publicKey.toString(\"hex\");\n\t\tconst participants = active\n\t\t\t.map(([publicKey, value]) => ({\n\t\t\t\tpublicKey,\n\t\t\t\tnickname: value.nickname,\n\t\t\t\tlabel: `${value.nickname}~${tags.get(publicKey) ?? formatIdentityLabel(value.nickname, value.publicKey).split(\"~\").at(-1)}`,\n\t\t\t\tmuted: value.muted,\n\t\t\t}))\n\t\t\t.sort((left, right) => left.label.localeCompare(right.label));\n\t\treturn {\n\t\t\tstate: this.state,\n\t\t\troom: this.room,\n\t\t\tlocalLabel: `${this.nickname}~${tags.get(localKey) ?? formatIdentityLabel(this.nickname, this.identity.publicKey).split(\"~\").at(-1)}`,\n\t\t\tparticipants,\n\t\t\tdirectNeighbors: [...this.peers.values()].filter(({ authenticated }) => authenticated).length,\n\t\t\tparticipantCatalogFull: this.participantCatalogFull,\n\t\t\ttranscript: this.transcript.map((entry) => {\n\t\t\t\tconst tag = tags.get(entry.publicKey);\n\t\t\t\tconst nickname = entry.label.split(\"~\", 1)[0] ?? entry.label;\n\t\t\t\treturn { ...entry, label: tag ? `${nickname}~${tag}` : entry.label };\n\t\t\t}),\n\t\t\tunread: this.unread,\n\t\t\tcomposerOpen: this.viewOpen,\n\t\t\t...(this.lastError ? { lastError: this.lastError } : {}),\n\t\t};\n\t}\n\n\tprivate onPeer(owner: number, peer: TransportPeer): void {\n\t\tif (owner !== this.generation || this.state === \"disconnected\") {\n\t\t\tpeer.close();\n\t\t\treturn;\n\t\t}\n\t\tconst id = keyId(peer.publicKey);\n\t\tif (id === this.identity.publicKey.toString(\"hex\")) {\n\t\t\tpeer.close();\n\t\t\treturn;\n\t\t}\n\t\tconst previous = this.peers.get(id);\n\t\tif (previous && previous.peer !== peer) previous.peer.close();\n\t\tconst state: PeerState = {\n\t\t\tpeer,\n\t\t\tauthenticated: false,\n\t\t\tnickname: previous?.nickname,\n\t\t\tviolations: 0,\n\t\t\tlimiter: new PeerRateLimiter({ burst: 12, refillPerSecond: 4, now: this.now }),\n\t\t};\n\t\tthis.peers.set(id, state);\n\t\ttry {\n\t\t\tpeer.send(\n\t\t\t\tcreateHello(\n\t\t\t\t\tthis.room,\n\t\t\t\t\tthis.nickname,\n\t\t\t\t\tthis.identity.publicKey,\n\t\t\t\t\tpeer.publicKey,\n\t\t\t\t\trandomBytes(16),\n\t\t\t\t),\n\t\t\t);\n\t\t} catch {\n\t\t\tpeer.close();\n\t\t\tthis.peers.delete(id);\n\t\t}\n\t}\n\n\tprivate onMessage(owner: number, peer: TransportPeer, message: ProtocolMessage): void {\n\t\tif (owner !== this.generation) return;\n\t\tconst id = keyId(peer.publicKey);\n\t\tconst state = this.peers.get(id);\n\t\tif (!state || state.peer !== peer) return;\n\t\tif (!state.authenticated) {\n\t\t\tconst hello = verifyHello(message, this.room, peer.publicKey, this.identity.publicKey);\n\t\t\tif (!hello) {\n\t\t\t\tthis.violate(id, state);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tstate.authenticated = true;\n\t\t\tstate.nickname = hello.nickname;\n\t\t\tthis.upsertParticipant(id, peer.publicKey, hello.nickname, this.now());\n\t\t\tthis.sendPresenceTo(state.peer);\n\t\t\tthis.emit();\n\t\t\treturn;\n\t\t}\n\t\tif (message.type === \"hello\") return;\n\t\tif (message.type === \"goodbye\") {\n\t\t\tthis.peers.delete(id);\n\t\t\tpeer.close();\n\t\t\tthis.emit();\n\t\t\treturn;\n\t\t}\n\t\tif (message.type !== \"gossip\") {\n\t\t\tthis.violate(id, state);\n\t\t\treturn;\n\t\t}\n\t\tthis.onGossip(id, state, message);\n\t}\n\n\tprivate onGossip(peerId: string, state: PeerState, message: GossipMessage): void {\n\t\tconst event = message.event;\n\t\tconst key = eventKey(event);\n\t\tif (event.origin === this.identity.publicKey.toString(\"hex\") || this.hasSeen(key)) return;\n\t\tif (!state.limiter.accept()) {\n\t\t\tthis.violate(peerId, state);\n\t\t\treturn;\n\t\t}\n\t\tif (!verifyRoomEvent(event, this.room, this.now())) {\n\t\t\tthis.violate(peerId, state);\n\t\t\treturn;\n\t\t}\n\t\tif (!this.acceptOrigin(event.origin)) return;\n\t\tthis.remember(key);\n\t\tif (!this.applyEvent(event)) return;\n\t\tif (message.hops > 1) {\n\t\t\tthis.broadcast(createGossipMessage(event, message.hops - 1), state.peer);\n\t\t}\n\t}\n\n\tprivate applyEvent(event: RoomEvent): boolean {\n\t\tconst publicKey = Buffer.from(event.origin, \"hex\");\n\t\tconst participantStateIsNew = this.acceptParticipantVersion(event);\n\t\tif (event.kind === \"presence\") {\n\t\t\tif (!participantStateIsNew) return false;\n\t\t\tif (event.status === \"leaving\") {\n\t\t\t\tthis.participants.delete(event.origin);\n\t\t\t\tthis.originLimiters.delete(event.origin);\n\t\t\t} else {\n\t\t\t\tthis.upsertParticipant(event.origin, publicKey, event.nickname, this.now());\n\t\t\t}\n\t\t\tthis.emit();\n\t\t\treturn true;\n\t\t}\n\t\tif (participantStateIsNew) {\n\t\t\tthis.upsertParticipant(event.origin, publicKey, event.nickname, this.now());\n\t\t}\n\t\tif (!this.mutedOrigins.has(event.origin)) {\n\t\t\tthis.pushTranscript({\n\t\t\t\tid: event.id,\n\t\t\t\tauthor: \"remote\",\n\t\t\t\tlabel: formatIdentityLabel(event.nickname, publicKey),\n\t\t\t\tpublicKey: event.origin,\n\t\t\t\ttext: event.text,\n\t\t\t\tsentAt: event.issuedAt,\n\t\t\t});\n\t\t\tif (!this.viewOpen) this.unread += 1;\n\t\t}\n\t\tthis.emit();\n\t\treturn true;\n\t}\n\n\tprivate acceptParticipantVersion(event: RoomEvent): boolean {\n\t\tthis.pruneParticipantVersions();\n\t\tconst existing = this.participantVersions.get(event.origin);\n\t\tif (existing && compareEventVersion(existing, event) >= 0) return false;\n\t\tif (!existing && this.participantVersions.size >= MAX_SEEN_MESSAGES) {\n\t\t\tlet oldestOrigin: string | undefined;\n\t\t\tlet oldestVersion: ParticipantVersionState | undefined;\n\t\t\tfor (const [origin, candidate] of this.participantVersions) {\n\t\t\t\tif (!oldestVersion || compareEventVersion(candidate, oldestVersion) < 0) {\n\t\t\t\t\toldestOrigin = origin;\n\t\t\t\t\toldestVersion = candidate;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (oldestOrigin) this.participantVersions.delete(oldestOrigin);\n\t\t}\n\t\tthis.participantVersions.set(event.origin, {\n\t\t\tissuedAt: event.issuedAt,\n\t\t\tid: event.id,\n\t\t});\n\t\treturn true;\n\t}\n\n\tprivate pruneParticipantVersions(): void {\n\t\tconst oldest = this.now() - MAX_EVENT_AGE_MS;\n\t\tfor (const [origin, version] of this.participantVersions) {\n\t\t\tif (version.issuedAt < oldest) this.participantVersions.delete(origin);\n\t\t}\n\t}\n\n\tprivate onDisconnect(owner: number, peer: TransportPeer): void {\n\t\tif (owner !== this.generation) return;\n\t\tconst id = keyId(peer.publicKey);\n\t\tif (this.peers.get(id)?.peer === peer) {\n\t\t\tthis.peers.delete(id);\n\t\t\tthis.emit();\n\t\t}\n\t}\n\n\tprivate onError(owner: number, error: Error): void {\n\t\tif (owner !== this.generation) return;\n\t\tthis.state = \"degraded\";\n\t\tthis.lastError = safeError(error);\n\t\tthis.emit();\n\t}\n\n\tprivate startHeartbeat(owner: number): void {\n\t\tthis.heartbeatTimer = setInterval(() => {\n\t\t\tif (owner !== this.generation || this.state === \"disconnected\") return;\n\t\t\tthis.publishPresence(\"online\");\n\t\t\tthis.pruneParticipants();\n\t\t\tthis.emit();\n\t\t}, PRESENCE_HEARTBEAT_MS);\n\t\tthis.heartbeatTimer.unref();\n\t}\n\n\tprivate publishPresence(status: \"online\" | \"leaving\"): void {\n\t\tconst event = this.newPresence(status);\n\t\tthis.broadcast(createGossipMessage(event));\n\t}\n\n\tprivate sendPresenceTo(peer: TransportPeer): void {\n\t\tconst event = this.currentPresence ?? this.newPresence(\"online\");\n\t\ttry {\n\t\t\tpeer.send(createGossipMessage(event));\n\t\t} catch {\n\t\t\t// The transport will publish disconnect state.\n\t\t}\n\t}\n\n\tprivate newPresence(status: \"online\" | \"leaving\"): PresenceEvent {\n\t\tconst event = createPresenceEvent(\n\t\t\tthis.room,\n\t\t\tthis.identity,\n\t\t\tthis.nickname,\n\t\t\tstatus,\n\t\t\tthis.now(),\n\t\t\trandomUUID(),\n\t\t);\n\t\tthis.currentPresence = status === \"online\" ? event : undefined;\n\t\tthis.remember(eventKey(event));\n\t\treturn event;\n\t}\n\n\tprivate broadcast(message: GossipMessage, exclude?: TransportPeer): number {\n\t\tlet relayedTo = 0;\n\t\tfor (const state of this.peers.values()) {\n\t\t\tif (!state.authenticated || state.peer === exclude) continue;\n\t\t\ttry {\n\t\t\t\tstate.peer.send(message);\n\t\t\t\trelayedTo += 1;\n\t\t\t} catch {\n\t\t\t\tstate.violations += 1;\n\t\t\t}\n\t\t}\n\t\treturn relayedTo;\n\t}\n\n\tprivate upsertParticipant(\n\t\tid: string,\n\t\tpublicKey: Buffer,\n\t\tnickname: string,\n\t\tlastSeen: number,\n\t): void {\n\t\tconst existing = this.participants.get(id);\n\t\tif (!existing && this.participants.size >= MAX_PARTICIPANTS) {\n\t\t\tthis.participantCatalogFull = true;\n\t\t\treturn;\n\t\t}\n\t\tthis.participants.set(id, {\n\t\t\tpublicKey: Buffer.from(publicKey),\n\t\t\tnickname,\n\t\t\tmuted: this.mutedOrigins.has(id),\n\t\t\tlastSeen,\n\t\t});\n\t}\n\n\tprivate pruneParticipants(): void {\n\t\tthis.pruneParticipantVersions();\n\t\tconst oldest = this.now() - PARTICIPANT_TTL_MS;\n\t\tfor (const [id, participant] of this.participants) {\n\t\t\tif (participant.lastSeen < oldest) {\n\t\t\t\tthis.participants.delete(id);\n\t\t\t\tthis.originLimiters.delete(id);\n\t\t\t}\n\t\t}\n\t\tif (this.participants.size < MAX_PARTICIPANTS) this.participantCatalogFull = false;\n\t}\n\n\tprivate acceptOrigin(origin: string): boolean {\n\t\tconst current = this.now();\n\t\tlet state = this.originLimiters.get(origin);\n\t\tif (!state) {\n\t\t\tif (this.originLimiters.size >= MAX_ORIGIN_LIMITERS) {\n\t\t\t\tlet oldestKey: string | undefined;\n\t\t\t\tlet oldest = Number.POSITIVE_INFINITY;\n\t\t\t\tfor (const [key, candidate] of this.originLimiters) {\n\t\t\t\t\tif (candidate.lastSeen < oldest) {\n\t\t\t\t\t\toldest = candidate.lastSeen;\n\t\t\t\t\t\toldestKey = key;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (oldestKey) this.originLimiters.delete(oldestKey);\n\t\t\t}\n\t\t\tstate = {\n\t\t\t\tlimiter: new PeerRateLimiter({ burst: 6, refillPerSecond: 1, now: this.now }),\n\t\t\t\tlastSeen: current,\n\t\t\t};\n\t\t\tthis.originLimiters.set(origin, state);\n\t\t}\n\t\tstate.lastSeen = current;\n\t\treturn state.limiter.accept();\n\t}\n\n\tprivate hasSeen(key: string): boolean {\n\t\tthis.pruneSeen();\n\t\treturn this.seen.has(key);\n\t}\n\n\tprivate remember(key: string): void {\n\t\tthis.pruneSeen();\n\t\tconst expiresAt = this.now() + SEEN_MESSAGE_TTL_MS;\n\t\tthis.seen.set(key, expiresAt);\n\t\tthis.seenOrder.push({ key, expiresAt });\n\t\twhile (this.seen.size > MAX_SEEN_MESSAGES) {\n\t\t\tconst removed = this.seenOrder.shift();\n\t\t\tif (removed && this.seen.get(removed.key) === removed.expiresAt) {\n\t\t\t\tthis.seen.delete(removed.key);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate pruneSeen(): void {\n\t\tconst current = this.now();\n\t\twhile (this.seenOrder[0] && this.seenOrder[0].expiresAt <= current) {\n\t\t\tconst removed = this.seenOrder.shift();\n\t\t\tif (removed && this.seen.get(removed.key) === removed.expiresAt) {\n\t\t\t\tthis.seen.delete(removed.key);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate violate(id: string, state: PeerState): void {\n\t\tstate.violations += 1;\n\t\tif (state.violations > MAX_PROTOCOL_VIOLATIONS) {\n\t\t\tstate.peer.close();\n\t\t\tthis.peers.delete(id);\n\t\t\tthis.emit();\n\t\t}\n\t}\n\n\tprivate pushTranscript(entry: TranscriptEntry): void {\n\t\tthis.transcript.push(entry);\n\t\tif (this.transcript.length > MAX_TRANSCRIPT) this.transcript.shift();\n\t}\n\n\tprivate async leaveOwned(): Promise<void> {\n\t\tthis.generation += 1;\n\t\tif (this.heartbeatTimer) clearInterval(this.heartbeatTimer);\n\t\tthis.heartbeatTimer = undefined;\n\t\tif (this.state !== \"disconnected\") this.publishPresence(\"leaving\");\n\t\tfor (const state of this.peers.values()) {\n\t\t\tif (state.authenticated) {\n\t\t\t\ttry {\n\t\t\t\t\tstate.peer.send({ v: 2, type: \"goodbye\" });\n\t\t\t\t} catch {\n\t\t\t\t\t// Best-effort departure notice.\n\t\t\t\t}\n\t\t\t}\n\t\t\tstate.peer.close();\n\t\t}\n\t\tthis.peers.clear();\n\t\tthis.participants.clear();\n\t\tthis.originLimiters.clear();\n\t\tthis.participantVersions.clear();\n\t\tthis.seen.clear();\n\t\tthis.seenOrder.length = 0;\n\t\tawait this.transport.stop().catch((error) => {\n\t\t\tthis.lastError = safeError(error);\n\t\t});\n\t\tthis.state = \"disconnected\";\n\t\tthis.unread = 0;\n\t\tthis.transcript.length = 0;\n\t\tthis.emit();\n\t}\n\n\tprivate emit(): void {\n\t\tconst snapshot = this.snapshot();\n\t\tthis.onChange?.(snapshot);\n\t\tfor (const listener of this.listeners) listener(snapshot);\n\t}\n}\n\nfunction eventKey(event: RoomEvent): string {\n\treturn `${event.origin}:${event.id}`;\n}\n\nfunction compareEventVersion(\n\tleft: Pick<RoomEvent, \"issuedAt\" | \"id\">,\n\tright: Pick<RoomEvent, \"issuedAt\" | \"id\">,\n): number {\n\treturn left.issuedAt - right.issuedAt || left.id.localeCompare(right.id);\n}\n\nfunction keyId(publicKey: Uint8Array): string {\n\treturn Buffer.from(publicKey).toString(\"hex\");\n}\n\nfunction safeError(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,eAAe,uBAAuB;;;ACA/C,SAAS,aAAa,kBAAkB;AAmBxC,IAAM,iBAAiB;AACvB,IAAM,oBAAoB;AAC1B,IAAM,sBAAsB,KAAK;AACjC,IAAM,0BAA0B;AAChC,IAAM,mBAAmB;AACzB,IAAM,qBAAqB;AAC3B,IAAM,wBAAwB;AAC9B,IAAM,sBAAsB;AAqFrB,IAAM,cAAN,MAAkB;AAAA,EACP;AAAA,EACA;AAAA,EACT;AAAA,EACS;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ,oBAAI,IAAuB;AAAA,EACnC,eAAe,oBAAI,IAA8B;AAAA,EACjD,eAAe,oBAAI,IAAY;AAAA,EAC/B,aAAgC,CAAC;AAAA,EACjC,OAAO,oBAAI,IAAoB;AAAA,EAC/B,YAAuD,CAAC;AAAA,EACxD,iBAAiB,oBAAI,IAAgC;AAAA,EACrD,sBAAsB,oBAAI,IAAqC;AAAA,EAC/D,YAAY,oBAAI,IAAsC;AAAA,EAC/D,QAA+B;AAAA,EAC/B,SAAS;AAAA,EACT,WAAW;AAAA,EACX;AAAA,EACA,aAAa;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA,yBAAyB;AAAA,EAEjC,YAAY,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,eAAe,gBACd,MACA,WAC8B;AAC9B,MAAI;AACH,UAAM,SAAS,MAAM,KAAK;AAC1B,WAAO,UAAU,IAAI,SAAS;AAAA,EAC/B,SAAS,OAAO;AACf,QAAI,CAAC,UAAU,EAAG,QAAO;AACzB,UAAM;AAAA,EACP;AACD;AAEA,SAAS,mBAA2B,MAAoD;AACvF,MAAI;AACJ,SAAO,MAAM;AACZ,QAAI,CAAC,SAAS;AACb,gBAAU,KAAK,EAAE,MAAM,CAAC,UAAU;AACjC,kBAAU;AACV,cAAM;AAAA,MACP,CAAC;AAAA,IACF;AACA,WAAO;AAAA,EACR;AACD;AAEA,IAAO,kBAAQ,sBAAsB;",
|
|
4
|
+
"sourcesContent": ["import { randomBytes as nodeRandomBytes } from \"node:crypto\";\nimport type {\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n} from \"@earendil-works/pi-coding-agent\";\nimport type { ChatSnapshot, ChatTransport } from \"./chat-session.js\";\nimport { ChatSession } from \"./chat-session.js\";\nimport type { PublicRoomDirectory } from \"./directory-network.js\";\nimport {\n\ttype ChatIdentity,\n\tcreateIdentity,\n\tderiveScopedIdentity,\n\tformatIdentityLabel,\n} from \"./identity.js\";\nimport type { ChatMenuSource, JoinRoomOptions } from \"./menu.js\";\nimport { type HyperswarmTransportOptions, MAX_DIRECT_NEIGHBORS } from \"./network-contract.js\";\nimport { createPrivateRoom, createPublicRoom, parseInvite, type RoomDescriptor } from \"./room.js\";\nimport {\n\tawaitChatSettingsWrites,\n\ttype ChatSettings,\n\tchatSettingsPath,\n\tdescriptorFromRememberedRoom,\n\treadChatSettings,\n\trememberedRoomFromDescriptor,\n\tupdateChatSettings as updateChatSettingsFile,\n\ttype WidgetMode,\n} from \"./settings.js\";\nimport { sanitizeSingleLine } from \"./text.js\";\n\nconst CHAT_UI_KEY = \"chat\";\nconst USAGE = \"Usage: /chat, /chat <pichat:v1-or-v2:invite>, or /chat #<public-slug>\";\nconst PRIVATE_ROOM_OPTIONS = [\n\t\"Join and remember \u2014 Save the bearer invite privately and restore this room\",\n\t\"Join once \u2014 Do not save the bearer invite\",\n\t\"Cancel\",\n] as const;\nconst DISPLAY_OPTIONS: ReadonlyArray<{ label: string; mode: WidgetMode }> = [\n\t{\n\t\tlabel: \"Room dock \u2014 Show up to three recent messages above the Pi editor\",\n\t\tmode: \"dock\",\n\t},\n\t{ label: \"Latest message \u2014 Show one recent message above the Pi editor\", mode: \"latest\" },\n\t{ label: \"Status only \u2014 Hide message text\", mode: \"count\" },\n\t{ label: \"Hidden \u2014 Show no persistent room widget\", mode: \"off\" },\n];\n\nexport interface PiChatDirectoryOptions {\n\tidentity: ChatIdentity;\n\tadvertisedSlug?: string;\n}\n\ntype Awaitable<Value> = Value | Promise<Value>;\ntype ChatMenuModule = Pick<typeof import(\"./menu.js\"), \"showChatMenu\">;\ntype ChatViewModule = Pick<typeof import(\"./chat-view.js\"), \"ChatView\">;\ntype ChatWidgetModule = Pick<typeof import(\"./widget.js\"), \"renderChatWidget\">;\n\nexport interface PiChatDependencies {\n\tsettingsPath: string;\n\trandomBytes(size: number): Buffer;\n\tcreateTransport(options: HyperswarmTransportOptions): Awaitable<ChatTransport>;\n\tcreateDirectory(options: PiChatDirectoryOptions): Awaitable<PublicRoomDirectory>;\n\tupdateSettings: typeof updateChatSettingsFile;\n\tloadChatMenu(): Promise<ChatMenuModule>;\n\tloadChatView(): Promise<ChatViewModule>;\n\tloadChatWidget(): Promise<ChatWidgetModule>;\n}\n\nexport function createPiChatExtension(\n\tdependencies: Partial<PiChatDependencies> = {},\n): (pi: ExtensionAPI) => void {\n\tconst loadNetwork = cachedModuleLoader(() => import(\"./network.js\"));\n\tconst loadDirectoryNetwork = cachedModuleLoader(() => import(\"./directory-network.js\"));\n\tconst deps: PiChatDependencies = {\n\t\tsettingsPath: dependencies.settingsPath ?? chatSettingsPath(),\n\t\trandomBytes: dependencies.randomBytes ?? nodeRandomBytes,\n\t\tcreateTransport:\n\t\t\tdependencies.createTransport ??\n\t\t\t(async (options) => {\n\t\t\t\tconst { HyperswarmTransport } = await loadNetwork();\n\t\t\t\treturn new HyperswarmTransport(options);\n\t\t\t}),\n\t\tcreateDirectory:\n\t\t\tdependencies.createDirectory ??\n\t\t\t(async (options) => {\n\t\t\t\tconst { HyperswarmDirectoryTransport, PublicRoomDirectorySession } =\n\t\t\t\t\tawait loadDirectoryNetwork();\n\t\t\t\treturn new PublicRoomDirectorySession({\n\t\t\t\t\t...options,\n\t\t\t\t\ttransport: new HyperswarmDirectoryTransport({ identity: options.identity }),\n\t\t\t\t});\n\t\t\t}),\n\t\tupdateSettings: dependencies.updateSettings ?? updateChatSettingsFile,\n\t\tloadChatMenu: cachedModuleLoader(dependencies.loadChatMenu ?? (() => import(\"./menu.js\"))),\n\t\tloadChatView: cachedModuleLoader(dependencies.loadChatView ?? (() => import(\"./chat-view.js\"))),\n\t\tloadChatWidget: cachedModuleLoader(\n\t\t\tdependencies.loadChatWidget ?? (() => import(\"./widget.js\")),\n\t\t),\n\t};\n\tconst updateChatSettings = deps.updateSettings;\n\n\treturn function piChatExtension(pi: ExtensionAPI): void {\n\t\tlet generation = 0;\n\t\tlet controller = new AbortController();\n\t\tlet activeSessionManager: unknown;\n\t\tlet activeContext: ExtensionContext | undefined;\n\t\tlet settings: ChatSettings = {};\n\t\tlet chatSession: ChatSession | undefined;\n\t\tlet roomDirectory: PublicRoomDirectory | undefined;\n\t\tlet latestSnapshot: ChatSnapshot | undefined;\n\t\tlet chatDraft = \"\";\n\t\tlet restoreError: string | undefined;\n\t\tlet restoringRoomId: string | undefined;\n\t\tlet joinOwner: { sessionManager: unknown; generation: number; token: symbol } | undefined;\n\t\tconst ownedTasks = new Set<Promise<unknown>>();\n\t\tlet renderChatWidget: ChatWidgetModule[\"renderChatWidget\"] | undefined;\n\t\tlet widgetRender: (() => void) | undefined;\n\t\tlet widgetInstalled = false;\n\n\t\tconst isCurrent = (owner: unknown, ownerGeneration: number) =>\n\t\t\tactiveSessionManager === owner &&\n\t\t\tgeneration === ownerGeneration &&\n\t\t\t!controller.signal.aborted;\n\n\t\tconst trackTask = <T>(task: Promise<T>): Promise<T> => {\n\t\t\townedTasks.add(task);\n\t\t\tvoid task.then(\n\t\t\t\t() => ownedTasks.delete(task),\n\t\t\t\t() => ownedTasks.delete(task),\n\t\t\t);\n\t\t\treturn task;\n\t\t};\n\n\t\tconst drainOwnedTasks = async (): Promise<void> => {\n\t\t\twhile (ownedTasks.size > 0) await Promise.allSettled([...ownedTasks]);\n\t\t};\n\n\t\tconst clearUi = (ctx: ExtensionContext, ownerGeneration = generation): void => {\n\t\t\ttry {\n\t\t\t\tctx.ui.setWidget(CHAT_UI_KEY, undefined);\n\t\t\t\tctx.ui.setStatus(CHAT_UI_KEY, undefined);\n\t\t\t} catch {\n\t\t\t\t// Session replacement may invalidate an old UI immediately.\n\t\t\t}\n\t\t\tif (ctx.sessionManager !== activeSessionManager || generation !== ownerGeneration) return;\n\t\t\trenderChatWidget = undefined;\n\t\t\twidgetRender = undefined;\n\t\t\twidgetInstalled = false;\n\t\t};\n\n\t\tconst updateUi = (ctx: ExtensionContext, snapshot?: ChatSnapshot): void => {\n\t\t\tif (ctx.sessionManager !== activeSessionManager) return;\n\t\t\tlatestSnapshot = snapshot;\n\t\t\ttry {\n\t\t\t\tctx.ui.setStatus(\n\t\t\t\t\tCHAT_UI_KEY,\n\t\t\t\t\tsnapshot?.state === \"connecting\"\n\t\t\t\t\t\t? restoringRoomId === snapshot.room.id\n\t\t\t\t\t\t\t? `chat: restoring ${sanitizeSingleLine(snapshot.room.label)}`\n\t\t\t\t\t\t\t: \"chat: joining\"\n\t\t\t\t\t\t: snapshot?.state === \"degraded\"\n\t\t\t\t\t\t\t? \"chat: reconnecting\"\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t);\n\t\t\t\tconst mode = settings.widgetMode ?? \"count\";\n\t\t\t\tif (\n\t\t\t\t\tctx.mode !== \"tui\" ||\n\t\t\t\t\t!snapshot ||\n\t\t\t\t\tsnapshot.state === \"disconnected\" ||\n\t\t\t\t\tmode === \"off\"\n\t\t\t\t) {\n\t\t\t\t\tctx.ui.setWidget(CHAT_UI_KEY, undefined);\n\t\t\t\t\twidgetInstalled = false;\n\t\t\t\t\twidgetRender = undefined;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst renderWidget = renderChatWidget;\n\t\t\t\tif (!renderWidget) return;\n\t\t\t\tif (!widgetInstalled) {\n\t\t\t\t\tctx.ui.setWidget(CHAT_UI_KEY, (tui, theme) => {\n\t\t\t\t\t\tconst requestRender = () => tui.requestRender();\n\t\t\t\t\t\twidgetRender = requestRender;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\trender: (width: number) =>\n\t\t\t\t\t\t\t\tlatestSnapshot\n\t\t\t\t\t\t\t\t\t? renderWidget(\n\t\t\t\t\t\t\t\t\t\t\tlatestSnapshot,\n\t\t\t\t\t\t\t\t\t\t\tsettings.widgetMode ?? \"count\",\n\t\t\t\t\t\t\t\t\t\t\twidth,\n\t\t\t\t\t\t\t\t\t\t\ttheme,\n\t\t\t\t\t\t\t\t\t\t\ttui.terminal.rows,\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t: [],\n\t\t\t\t\t\t\tinvalidate() {},\n\t\t\t\t\t\t\tdispose() {\n\t\t\t\t\t\t\t\tif (widgetRender === requestRender) widgetRender = undefined;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t});\n\t\t\t\t\twidgetInstalled = true;\n\t\t\t\t}\n\t\t\t\twidgetRender?.();\n\t\t\t} catch {\n\t\t\t\t// UI updates are best-effort after replacement.\n\t\t\t}\n\t\t};\n\n\t\tconst disconnectRoom = async (): Promise<void> => {\n\t\t\tconst owned = chatSession;\n\t\t\tconst ownedDirectory = roomDirectory;\n\t\t\tconst uiContext = activeContext;\n\t\t\tconst uiGeneration = generation;\n\t\t\tchatSession = undefined;\n\t\t\troomDirectory = undefined;\n\t\t\tlatestSnapshot = undefined;\n\t\t\tchatDraft = \"\";\n\t\t\tawait Promise.allSettled([owned?.leave(), ownedDirectory?.stop()]);\n\t\t\tif (uiContext) clearUi(uiContext, uiGeneration);\n\t\t};\n\n\t\tconst ensureIdentity = async (\n\t\t\tctx: ExtensionContext,\n\t\t\tsignal: AbortSignal,\n\t\t\towner: unknown,\n\t\t\townerGeneration: number,\n\t\t): Promise<ChatIdentity | undefined> => {\n\t\t\tlet nickname = settings.nickname;\n\t\t\tif (!nickname) {\n\t\t\t\tconst entered = await ctx.ui.input(\n\t\t\t\t\t\"Choose a Pi Chat nickname\",\n\t\t\t\t\t\"Visible to room peers; no OS or Git identity is used\",\n\t\t\t\t\t{ signal },\n\t\t\t\t);\n\t\t\t\tif (!isCurrent(owner, ownerGeneration) || signal.aborted || !entered) return undefined;\n\t\t\t\tnickname = entered;\n\t\t\t}\n\t\t\tlet seed = settings.identitySeed;\n\t\t\tlet widgetMode = settings.widgetMode;\n\t\t\tif (!seed) {\n\t\t\t\tconst candidate = createIdentity(deps.randomBytes(32));\n\t\t\t\tif (!widgetMode) {\n\t\t\t\t\tconst selected = await ctx.ui.select(\n\t\t\t\t\t\t\"Joined room display\",\n\t\t\t\t\t\tDISPLAY_OPTIONS.map(({ label }) => label),\n\t\t\t\t\t\t{ signal },\n\t\t\t\t\t);\n\t\t\t\t\tif (!selected || !isCurrent(owner, ownerGeneration) || signal.aborted) return undefined;\n\t\t\t\t\twidgetMode = DISPLAY_OPTIONS.find(({ label }) => label === selected)?.mode;\n\t\t\t\t\tif (!widgetMode) return undefined;\n\t\t\t\t}\n\t\t\t\tconst display =\n\t\t\t\t\tDISPLAY_OPTIONS.find(({ mode }) => mode === widgetMode)?.label ?? widgetMode;\n\t\t\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t\t\t\"Create Pi Chat identity?\",\n\t\t\t\t\t`${formatIdentityLabel(nickname, candidate.publicKey)}\\nDisplay: ${display}\\nThis pseudonymous fingerprint is not real-world identity verification.`,\n\t\t\t\t\t{ signal },\n\t\t\t\t);\n\t\t\t\tif (!confirmed || !isCurrent(owner, ownerGeneration) || signal.aborted) return undefined;\n\t\t\t\tseed = candidate.seed;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tnickname !== settings.nickname ||\n\t\t\t\tseed !== settings.identitySeed ||\n\t\t\t\twidgetMode !== settings.widgetMode\n\t\t\t) {\n\t\t\t\tconst updated = await updateChatSettings(\n\t\t\t\t\t{\n\t\t\t\t\t\tnickname,\n\t\t\t\t\t\tidentitySeed: seed,\n\t\t\t\t\t\t...(widgetMode ? { widgetMode } : {}),\n\t\t\t\t\t},\n\t\t\t\t\t{ settingsPath: deps.settingsPath, signal },\n\t\t\t\t);\n\t\t\t\tif (!isCurrent(owner, ownerGeneration)) return undefined;\n\t\t\t\tsettings = updated;\n\t\t\t}\n\t\t\treturn createIdentity(Buffer.from(seed, \"base64url\"));\n\t\t};\n\n\t\tconst startPublicRoomDirectory = (\n\t\t\troom: RoomDescriptor,\n\t\t\tidentity: ChatIdentity,\n\t\t\tsession: ChatSession,\n\t\t\tctx: ExtensionContext,\n\t\t\towner: unknown,\n\t\t\townerGeneration: number,\n\t\t): void => {\n\t\t\tif (room.kind !== \"public\" || !room.slug) return;\n\t\t\tvoid trackTask(\n\t\t\t\t(async () => {\n\t\t\t\t\tlet directory: PublicRoomDirectory | undefined;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tdirectory = await deps.createDirectory({\n\t\t\t\t\t\t\tidentity: deriveScopedIdentity(identity, `directory:#${room.slug}`),\n\t\t\t\t\t\t\tadvertisedSlug: room.slug,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t!isCurrent(owner, ownerGeneration) ||\n\t\t\t\t\t\t\tcontroller.signal.aborted ||\n\t\t\t\t\t\t\tchatSession !== session\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tawait directory.stop();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\troomDirectory = directory;\n\t\t\t\t\t\tawait directory.start(controller.signal);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconst ownsDirectory = !directory || roomDirectory === directory;\n\t\t\t\t\t\tif (directory && roomDirectory === directory) roomDirectory = undefined;\n\t\t\t\t\t\tif (directory) await Promise.allSettled([directory.stop()]);\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\townsDirectory &&\n\t\t\t\t\t\t\tisCurrent(owner, ownerGeneration) &&\n\t\t\t\t\t\t\tchatSession === session &&\n\t\t\t\t\t\t\tsession.snapshot().room.id === room.id\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tnotifySafely(\n\t\t\t\t\t\t\t\tctx,\n\t\t\t\t\t\t\t\t`Pi Chat public-room discovery is unavailable: ${sanitizeSingleLine(\n\t\t\t\t\t\t\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t\t\t\t\t\t)}. Chat remains connected.`,\n\t\t\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t})(),\n\t\t\t);\n\t\t};\n\n\t\tconst joinRoomOwned = async (\n\t\t\troom: RoomDescriptor,\n\t\t\tctx: ExtensionContext,\n\t\t\tsignal: AbortSignal,\n\t\t\toptions?: JoinRoomOptions,\n\t\t): Promise<boolean> => {\n\t\t\tif (chatSession && latestSnapshot?.state !== \"disconnected\") {\n\t\t\t\tthrow new Error(\"Leave the current Pi Chat room before joining another.\");\n\t\t\t}\n\t\t\tconst owner = ctx.sessionManager;\n\t\t\tconst ownerGeneration = generation;\n\t\t\tif (!isCurrent(owner, ownerGeneration)) throw new Error(\"Pi Chat session is stale.\");\n\t\t\tlet remember = options?.remember ?? false;\n\t\t\tif (room.kind === \"private\" && options === undefined) {\n\t\t\t\tconst selected = await ctx.ui.select(\n\t\t\t\t\t\"Private bearer invite \u2014 restore this room after restarting Pi?\",\n\t\t\t\t\t[...PRIVATE_ROOM_OPTIONS],\n\t\t\t\t\t{ signal },\n\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\t!selected ||\n\t\t\t\t\tselected === PRIVATE_ROOM_OPTIONS[2] ||\n\t\t\t\t\t!isCurrent(owner, ownerGeneration) ||\n\t\t\t\t\tsignal.aborted\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tremember = selected === PRIVATE_ROOM_OPTIONS[0];\n\t\t\t}\n\t\t\tconst identity = await ensureIdentity(ctx, signal, owner, ownerGeneration);\n\t\t\tif (!identity || !isCurrent(owner, ownerGeneration) || signal.aborted) return false;\n\t\t\tconst nickname = settings.nickname;\n\t\t\tif (!nickname) throw new Error(\"Pi Chat nickname is unavailable.\");\n\t\t\tconst widgetModule = await loadOwnedModule(\n\t\t\t\tdeps.loadChatWidget,\n\t\t\t\t() => isCurrent(owner, ownerGeneration) && !signal.aborted,\n\t\t\t);\n\t\t\tif (!widgetModule) return false;\n\t\t\tlet transport: ChatTransport;\n\t\t\ttry {\n\t\t\t\ttransport = await deps.createTransport({\n\t\t\t\t\troom,\n\t\t\t\t\tidentity,\n\t\t\t\t\tmaxPeers: MAX_DIRECT_NEIGHBORS,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tif (!isCurrent(owner, ownerGeneration) || signal.aborted) return false;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tif (!isCurrent(owner, ownerGeneration) || signal.aborted) {\n\t\t\t\tawait transport.stop();\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\trenderChatWidget = widgetModule.renderChatWidget;\n\t\t\tconst session = new ChatSession({\n\t\t\t\troom,\n\t\t\t\tidentity,\n\t\t\t\tnickname,\n\t\t\t\ttransport,\n\t\t\t\tonChange: (snapshot) => {\n\t\t\t\t\tif (chatSession !== session || !isCurrent(owner, ownerGeneration)) return;\n\t\t\t\t\tupdateUi(ctx, snapshot);\n\t\t\t\t},\n\t\t\t});\n\t\t\tchatSession = session;\n\t\t\tctx.ui.setStatus(CHAT_UI_KEY, \"chat: joining\");\n\t\t\ttry {\n\t\t\t\tawait session.start(AbortSignal.any([signal, controller.signal]));\n\t\t\t\tif (!isCurrent(owner, ownerGeneration) || chatSession !== session) {\n\t\t\t\t\tawait session.leave();\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tif (remember) {\n\t\t\t\t\tconst rememberedRoom = rememberedRoomFromDescriptor(room);\n\t\t\t\t\tconst next = await updateChatSettings(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tresume: {\n\t\t\t\t\t\t\t\trooms: [rememberedRoom],\n\t\t\t\t\t\t\t\tactiveRoomId: rememberedRoom.id,\n\t\t\t\t\t\t\t\tsurface: \"chat\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ settingsPath: deps.settingsPath, signal },\n\t\t\t\t\t);\n\t\t\t\t\tif (!isCurrent(owner, ownerGeneration) || chatSession !== session) {\n\t\t\t\t\t\tawait session.leave();\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tsettings = next;\n\t\t\t\t}\n\t\t\t\trestoreError = undefined;\n\t\t\t\tlatestSnapshot = session.snapshot();\n\t\t\t\tupdateUi(ctx, latestSnapshot);\n\t\t\t\tstartPublicRoomDirectory(room, identity, session, ctx, owner, ownerGeneration);\n\t\t\t\treturn true;\n\t\t\t} catch (error) {\n\t\t\t\tif (chatSession === session) chatSession = undefined;\n\t\t\t\tawait session.leave();\n\t\t\t\tclearUi(ctx, ownerGeneration);\n\t\t\t\tif (!signal.aborted && isCurrent(owner, ownerGeneration)) throw error;\n\t\t\t\treturn false;\n\t\t\t}\n\t\t};\n\n\t\tconst joinRoom: typeof joinRoomOwned = async (room, ctx, signal, options) => {\n\t\t\tconst existing = joinOwner;\n\t\t\tif (existing?.sessionManager === ctx.sessionManager && existing.generation === generation) {\n\t\t\t\tthrow new Error(\"A Pi Chat room join is already in progress.\");\n\t\t\t}\n\t\t\tconst token = Symbol(\"chat-join\");\n\t\t\tjoinOwner = { sessionManager: ctx.sessionManager, generation, token };\n\t\t\ttry {\n\t\t\t\treturn await joinRoomOwned(room, ctx, signal, options);\n\t\t\t} finally {\n\t\t\t\tif (joinOwner?.token === token) joinOwner = undefined;\n\t\t\t}\n\t\t};\n\n\t\tconst updateRememberedSurface = async (\n\t\t\tsurface: \"chat\" | \"pi\",\n\t\t\tctx: ExtensionContext,\n\t\t\towner: unknown,\n\t\t\townerGeneration: number,\n\t\t\tsession: ChatSession,\n\t\t): Promise<void> => {\n\t\t\tconst resume = settings.resume;\n\t\t\tif (\n\t\t\t\t!resume ||\n\t\t\t\tresume.activeRoomId !== session.snapshot().room.id ||\n\t\t\t\tresume.surface === surface\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst next = await updateChatSettings(\n\t\t\t\t\t{ resume: { ...resume, surface } },\n\t\t\t\t\t{ settingsPath: deps.settingsPath, signal: controller.signal },\n\t\t\t\t);\n\t\t\t\tif (isCurrent(owner, ownerGeneration) && chatSession === session) settings = next;\n\t\t\t} catch (error) {\n\t\t\t\tif (isCurrent(owner, ownerGeneration) && chatSession === session) {\n\t\t\t\t\tnotifySafely(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\t`Pi Chat could not save the restart view: ${sanitizeSingleLine(error instanceof Error ? error.message : String(error))}.`,\n\t\t\t\t\t\t\"error\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tconst openChat = async (ctx: ExtensionContext): Promise<void> => {\n\t\t\tconst session = chatSession;\n\t\t\tif (!session || session.snapshot().state === \"disconnected\") {\n\t\t\t\tthrow new Error(\"Join a Pi Chat room first.\");\n\t\t\t}\n\t\t\tconst owner = ctx.sessionManager;\n\t\t\tconst ownerGeneration = generation;\n\t\t\tconst ownerSignal = controller.signal;\n\t\t\tawait updateRememberedSurface(\"chat\", ctx, owner, ownerGeneration, session);\n\t\t\tif (!isCurrent(owner, ownerGeneration) || chatSession !== session) return;\n\t\t\tconst viewModule = await loadOwnedModule(\n\t\t\t\tdeps.loadChatView,\n\t\t\t\t() => isCurrent(owner, ownerGeneration) && chatSession === session,\n\t\t\t);\n\t\t\tif (!viewModule) return;\n\t\t\tconst { ChatView } = viewModule;\n\t\t\tawait ctx.ui.custom<void>(\n\t\t\t\t(tui, theme, _keybindings, done) =>\n\t\t\t\t\tnew ChatView({\n\t\t\t\t\t\ttui,\n\t\t\t\t\t\ttheme,\n\t\t\t\t\t\tgetSnapshot: () => session.snapshot(),\n\t\t\t\t\t\tsend: (text) => session.send(text),\n\t\t\t\t\t\tinitialDraft: chatDraft,\n\t\t\t\t\t\tonDraftChange: (text) => {\n\t\t\t\t\t\t\tif (isCurrent(owner, ownerGeneration) && chatSession === session) chatDraft = text;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tsetViewOpen: (open) => session.setViewOpen(open),\n\t\t\t\t\t\tsubscribe: (listener) => session.subscribe(listener),\n\t\t\t\t\t\tsignal: ownerSignal,\n\t\t\t\t\t\tonReturnToPi: () => {\n\t\t\t\t\t\t\tvoid trackTask(updateRememberedSurface(\"pi\", ctx, owner, ownerGeneration, session));\n\t\t\t\t\t\t},\n\t\t\t\t\t\tonClose: () => done(undefined),\n\t\t\t\t\t}),\n\t\t\t);\n\t\t\tif (isCurrent(owner, ownerGeneration) && chatSession === session)\n\t\t\t\tupdateUi(ctx, session.snapshot());\n\t\t};\n\n\t\tconst restoreRememberedRoom = async (\n\t\t\tctx: ExtensionContext,\n\t\t\townerGeneration: number,\n\t\t\tsignal: AbortSignal = controller.signal,\n\t\t): Promise<void> => {\n\t\t\tconst resume = settings.resume;\n\t\t\tif (!resume || !settings.nickname || !settings.identitySeed || ctx.mode !== \"tui\") return;\n\t\t\tconst remembered = resume.rooms.find(({ id }) => id === resume.activeRoomId);\n\t\t\tif (!remembered || !isCurrent(ctx.sessionManager, ownerGeneration)) return;\n\t\t\tlet room: RoomDescriptor;\n\t\t\ttry {\n\t\t\t\troom = descriptorFromRememberedRoom(remembered);\n\t\t\t} catch {\n\t\t\t\tnotifySafely(ctx, \"Pi Chat could not restore the saved room; fix pi-chat.json.\", \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\trestoreError = undefined;\n\t\t\trestoringRoomId = room.id;\n\t\t\ttry {\n\t\t\t\tctx.ui.setStatus(CHAT_UI_KEY, `chat: restoring ${sanitizeSingleLine(room.label)}`);\n\t\t\t\tconst joined = await joinRoom(room, ctx, signal, { remember: false });\n\t\t\t\tif (!joined || signal.aborted || !isCurrent(ctx.sessionManager, ownerGeneration)) return;\n\t\t\t\tif (resume.surface === \"chat\") await openChat(ctx);\n\t\t\t} catch (error) {\n\t\t\t\tif (isCurrent(ctx.sessionManager, ownerGeneration)) {\n\t\t\t\t\trestoreError = sanitizeSingleLine(error instanceof Error ? error.message : String(error));\n\t\t\t\t\tctx.ui.setStatus(CHAT_UI_KEY, \"chat: restore failed\");\n\t\t\t\t\tnotifySafely(\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\t`Pi Chat could not restore ${sanitizeSingleLine(room.label)}: ${restoreError}. Use /chat to retry or forget it.`,\n\t\t\t\t\t\t\"error\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tif (restoringRoomId === room.id) restoringRoomId = undefined;\n\t\t\t}\n\t\t};\n\n\t\tconst menuSource = (ctx: ExtensionCommandContext): ChatMenuSource => {\n\t\t\tconst resetIdentity = createIdentity(deps.randomBytes(32));\n\t\t\tconst owner = ctx.sessionManager;\n\t\t\tconst ownerGeneration = generation;\n\t\t\tconst ownsMenu = () => isCurrent(owner, ownerGeneration);\n\t\t\treturn {\n\t\t\t\tsettingsPath: deps.settingsPath,\n\t\t\t\tgetSettings: () => settings,\n\t\t\t\tgetSnapshot: () => chatSession?.snapshot(),\n\t\t\t\tgetRestoreError: () => restoreError,\n\t\t\t\tcreatePrivateRoom: () => createPrivateRoom(deps.randomBytes(32)),\n\t\t\t\tbrowsePublicRooms: async (signal) => {\n\t\t\t\t\tif (!ownsMenu()) throw new Error(\"Pi Chat session is stale.\");\n\t\t\t\t\tconst activeDirectory = roomDirectory;\n\t\t\t\t\tconst directory =\n\t\t\t\t\t\tactiveDirectory ??\n\t\t\t\t\t\t(await deps.createDirectory({ identity: createIdentity(deps.randomBytes(32)) }));\n\t\t\t\t\tconst temporary = activeDirectory ? undefined : directory;\n\t\t\t\t\tconst browseSignal = AbortSignal.any([signal, controller.signal]);\n\t\t\t\t\tif (!ownsMenu() || browseSignal.aborted) {\n\t\t\t\t\t\tif (temporary) await temporary.stop();\n\t\t\t\t\t\tthrow browseSignal.reason ?? new DOMException(\"Aborted\", \"AbortError\");\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = await directory.browse(browseSignal);\n\t\t\t\t\t\tif (!ownsMenu() || browseSignal.aborted) {\n\t\t\t\t\t\t\tthrow browseSignal.reason ?? new DOMException(\"Aborted\", \"AbortError\");\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tif (temporary) await temporary.stop();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tjoinRoom,\n\t\t\t\topenChat: async (commandCtx) => {\n\t\t\t\t\tif (ownsMenu()) await openChat(commandCtx);\n\t\t\t\t},\n\t\t\t\tretryRememberedRoom: async (commandCtx, signal) => {\n\t\t\t\t\tif (!ownsMenu() || signal.aborted) return;\n\t\t\t\t\tawait restoreRememberedRoom(\n\t\t\t\t\t\tcommandCtx,\n\t\t\t\t\t\townerGeneration,\n\t\t\t\t\t\tAbortSignal.any([signal, controller.signal]),\n\t\t\t\t\t);\n\t\t\t\t\tif (restoreError) throw new Error(restoreError);\n\t\t\t\t},\n\t\t\t\tforgetRememberedRoom: async (signal) => {\n\t\t\t\t\tif (!ownsMenu()) return;\n\t\t\t\t\tif (settings.resume) {\n\t\t\t\t\t\tconst next = await updateChatSettings(\n\t\t\t\t\t\t\t{ resume: null },\n\t\t\t\t\t\t\t{ settingsPath: deps.settingsPath, signal },\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (!ownsMenu()) return;\n\t\t\t\t\t\tsettings = next;\n\t\t\t\t\t}\n\t\t\t\t\trestoreError = undefined;\n\t\t\t\t\tclearUi(ctx);\n\t\t\t\t},\n\t\t\t\tleaveRoom: async (signal) => {\n\t\t\t\t\tif (!ownsMenu()) return;\n\t\t\t\t\tconst currentRoomId = chatSession?.snapshot().room.id;\n\t\t\t\t\tif (settings.resume && settings.resume.activeRoomId === currentRoomId) {\n\t\t\t\t\t\tconst next = await updateChatSettings(\n\t\t\t\t\t\t\t{ resume: null },\n\t\t\t\t\t\t\t{ settingsPath: deps.settingsPath, signal },\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (!ownsMenu()) return;\n\t\t\t\t\t\tsettings = next;\n\t\t\t\t\t}\n\t\t\t\t\trestoreError = undefined;\n\t\t\t\t\tawait disconnectRoom();\n\t\t\t\t},\n\t\t\t\ttoggleMute(publicKey) {\n\t\t\t\t\tif (!ownsMenu() || !/^[0-9a-f]{64}$/u.test(publicKey)) return undefined;\n\t\t\t\t\tconst muted = chatSession?.toggleMute(Buffer.from(publicKey, \"hex\"));\n\t\t\t\t\tif (chatSession) updateUi(ctx, chatSession.snapshot());\n\t\t\t\t\treturn muted;\n\t\t\t\t},\n\t\t\t\tasync updateNickname(value, signal) {\n\t\t\t\t\tconst previous = settings;\n\t\t\t\t\tconst next = await updateChatSettings(\n\t\t\t\t\t\t{ nickname: value },\n\t\t\t\t\t\t{ settingsPath: deps.settingsPath, signal },\n\t\t\t\t\t);\n\t\t\t\t\tif (!ownsMenu()) return;\n\t\t\t\t\tsettings = next;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tchatSession?.updateNickname(value);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tsettings = previous;\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\t\t\t\t\tif (chatSession) updateUi(ctx, chatSession.snapshot());\n\t\t\t\t},\n\t\t\t\tasync updateWidgetMode(value, signal) {\n\t\t\t\t\tconst next = await updateChatSettings(\n\t\t\t\t\t\t{ widgetMode: value },\n\t\t\t\t\t\t{ settingsPath: deps.settingsPath, signal },\n\t\t\t\t\t);\n\t\t\t\t\tif (!ownsMenu()) return;\n\t\t\t\t\tsettings = next;\n\t\t\t\t\tupdateUi(ctx, chatSession?.snapshot());\n\t\t\t\t},\n\t\t\t\tgetIdentityResetPreview: () => {\n\t\t\t\t\tconst current = settings.identitySeed\n\t\t\t\t\t\t? formatIdentityLabel(\n\t\t\t\t\t\t\t\tsettings.nickname ?? \"anonymous\",\n\t\t\t\t\t\t\t\tcreateIdentity(Buffer.from(settings.identitySeed, \"base64url\")).publicKey,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: \"not created\";\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcurrent,\n\t\t\t\t\t\tnext: formatIdentityLabel(settings.nickname ?? \"anonymous\", resetIdentity.publicKey),\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\tasync resetIdentity(signal) {\n\t\t\t\t\tconst next = await updateChatSettings(\n\t\t\t\t\t\t{ identitySeed: resetIdentity.seed, resume: null },\n\t\t\t\t\t\t{ settingsPath: deps.settingsPath, signal },\n\t\t\t\t\t);\n\t\t\t\t\tif (!ownsMenu()) return;\n\t\t\t\t\tsettings = next;\n\t\t\t\t\tawait disconnectRoom();\n\t\t\t\t},\n\t\t\t};\n\t\t};\n\n\t\tpi.registerCommand(\"chat\", {\n\t\t\tdescription: \"Open peer-to-peer developer chat\",\n\t\t\thandler: async (args, ctx) => {\n\t\t\t\tif (ctx.mode !== \"tui\") throw new Error(\"Pi Chat requires Pi TUI mode.\");\n\t\t\t\tconst owner = ctx.sessionManager;\n\t\t\t\tconst ownerGeneration = generation;\n\t\t\t\tif (!isCurrent(owner, ownerGeneration)) throw new Error(\"Pi Chat session is stale.\");\n\t\t\t\tconst input = args.trim();\n\t\t\t\tif (!input) {\n\t\t\t\t\tconst menuModule = await loadOwnedModule(deps.loadChatMenu, () =>\n\t\t\t\t\t\tisCurrent(owner, ownerGeneration),\n\t\t\t\t\t);\n\t\t\t\t\tif (!menuModule) return;\n\t\t\t\t\tconst { showChatMenu } = menuModule;\n\t\t\t\t\tawait showChatMenu(ctx, menuSource(ctx), {\n\t\t\t\t\t\tsignal: controller.signal,\n\t\t\t\t\t\tisCurrent: () => isCurrent(owner, ownerGeneration),\n\t\t\t\t\t});\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (/\\s/u.test(input)) {\n\t\t\t\t\tnotifySafely(ctx, USAGE, \"warning\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlet room: RoomDescriptor;\n\t\t\t\tlet openAfterJoin = false;\n\t\t\t\tif (input.startsWith(\"pichat:\")) {\n\t\t\t\t\topenAfterJoin = true;\n\t\t\t\t\ttry {\n\t\t\t\t\t\troom = parseInvite(input);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tnotifySafely(ctx, USAGE, \"warning\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t} else if (input.startsWith(\"#\")) {\n\t\t\t\t\topenAfterJoin = true;\n\t\t\t\t\ttry {\n\t\t\t\t\t\troom = createPublicRoom(input.slice(1));\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tnotifySafely(ctx, USAGE, \"warning\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tconst confirmed = await ctx.ui.confirm(\n\t\t\t\t\t\t\"Join public room?\",\n\t\t\t\t\t\t\"Anyone can join or record it. DHT and direct peers may observe network metadata.\",\n\t\t\t\t\t\t{ signal: controller.signal },\n\t\t\t\t\t);\n\t\t\t\t\tif (!confirmed || !isCurrent(owner, ownerGeneration)) return;\n\t\t\t\t} else {\n\t\t\t\t\tnotifySafely(ctx, USAGE, \"warning\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst joined = await joinRoom(\n\t\t\t\t\troom,\n\t\t\t\t\tctx,\n\t\t\t\t\tcontroller.signal,\n\t\t\t\t\troom.kind === \"public\" ? { remember: true } : undefined,\n\t\t\t\t);\n\t\t\t\tif (\n\t\t\t\t\tjoined &&\n\t\t\t\t\topenAfterJoin &&\n\t\t\t\t\t!controller.signal.aborted &&\n\t\t\t\t\tisCurrent(owner, ownerGeneration)\n\t\t\t\t) {\n\t\t\t\t\tawait openChat(ctx);\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\n\t\tpi.on(\"session_start\", async (_event, ctx) => {\n\t\t\tcontroller.abort(new DOMException(\"Pi Chat session replaced\", \"AbortError\"));\n\t\t\tawait disconnectRoom();\n\t\t\tawait drainOwnedTasks();\n\t\t\tcontroller = new AbortController();\n\t\t\tgeneration += 1;\n\t\t\tactiveSessionManager = ctx.sessionManager;\n\t\t\tactiveContext = ctx;\n\t\t\trestoreError = undefined;\n\t\t\tclearUi(ctx);\n\t\t\tconst ownerGeneration = generation;\n\t\t\tconst loaded = await readChatSettings(deps.settingsPath);\n\t\t\tif (generation !== ownerGeneration || activeSessionManager !== ctx.sessionManager) return;\n\t\t\tif (loaded.kind === \"loaded\") settings = loaded.settings;\n\t\t\telse if (loaded.kind === \"missing\") settings = {};\n\t\t\telse {\n\t\t\t\tsettings = {};\n\t\t\t\tnotifySafely(ctx, \"Pi Chat settings are invalid; fix the file before saving.\", \"error\");\n\t\t\t}\n\t\t\tif (settings.resume && ctx.mode === \"tui\") {\n\t\t\t\tvoid trackTask(restoreRememberedRoom(ctx, ownerGeneration));\n\t\t\t}\n\t\t});\n\n\t\tpi.on(\"session_shutdown\", async (_event, ctx) => {\n\t\t\tconst owner = ctx.sessionManager;\n\t\t\tif (owner !== activeSessionManager) return;\n\t\t\tcontroller.abort(new DOMException(\"Pi Chat session shut down\", \"AbortError\"));\n\t\t\tconst shutdownGeneration = ++generation;\n\t\t\tawait disconnectRoom();\n\t\t\tawait drainOwnedTasks();\n\t\t\tawait awaitChatSettingsWrites(deps.settingsPath);\n\t\t\tif (activeSessionManager !== owner || generation !== shutdownGeneration) return;\n\t\t\tclearUi(ctx);\n\t\t\tactiveSessionManager = undefined;\n\t\t\tactiveContext = undefined;\n\t\t});\n\t};\n}\n\nfunction notifySafely(\n\tctx: ExtensionContext,\n\tmessage: string,\n\tlevel: \"info\" | \"warning\" | \"error\",\n): void {\n\ttry {\n\t\tctx.ui.notify(sanitizeSingleLine(message), level);\n\t} catch {\n\t\t// Stale UI errors must not escape lifecycle cleanup.\n\t}\n}\n\nasync function loadOwnedModule<Module>(\n\tload: () => Promise<Module>,\n\tisCurrent: () => boolean,\n): Promise<Module | undefined> {\n\ttry {\n\t\tconst module = await load();\n\t\treturn isCurrent() ? module : undefined;\n\t} catch (error) {\n\t\tif (!isCurrent()) return undefined;\n\t\tthrow error;\n\t}\n}\n\nfunction cachedModuleLoader<Module>(load: () => Promise<Module>): () => Promise<Module> {\n\tlet pending: Promise<Module> | undefined;\n\treturn () => {\n\t\tif (!pending) {\n\t\t\tpending = load().catch((error) => {\n\t\t\t\tpending = undefined;\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t}\n\t\treturn pending;\n\t};\n}\n\nexport default createPiChatExtension();\n", "import { randomBytes, randomUUID } from \"node:crypto\";\nimport type { ChatIdentity } from \"./identity.js\";\nimport { formatIdentityLabel, normalizeNickname, uniqueIdentityTags } from \"./identity.js\";\nimport {\n\tcreateChatEvent,\n\tcreateGossipMessage,\n\tcreateHello,\n\tcreatePresenceEvent,\n\ttype GossipMessage,\n\tMAX_EVENT_AGE_MS,\n\tPeerRateLimiter,\n\ttype PresenceEvent,\n\ttype ProtocolMessage,\n\ttype RoomDescriptor,\n\ttype RoomEvent,\n\tverifyHello,\n\tverifyRoomEvent,\n} from \"./protocol.js\";\n\nconst MAX_TRANSCRIPT = 256;\nconst MAX_SEEN_MESSAGES = 8_192;\nconst SEEN_MESSAGE_TTL_MS = 10 * 60_000;\nconst MAX_PROTOCOL_VIOLATIONS = 3;\nconst MAX_PARTICIPANTS = 256;\nconst PARTICIPANT_TTL_MS = 90_000;\nconst PRESENCE_HEARTBEAT_MS = 30_000;\nconst MAX_ORIGIN_LIMITERS = 512;\n\nexport interface TransportPeer {\n\tpublicKey: Buffer;\n\tsend(message: ProtocolMessage): void;\n\tclose(): void;\n}\n\nexport interface ChatTransportListener {\n\tonPeer(peer: TransportPeer): void;\n\tonMessage(peer: TransportPeer, message: ProtocolMessage): void;\n\tonDisconnect(peer: TransportPeer): void;\n\tonError(error: Error): void;\n}\n\nexport interface ChatTransport {\n\tstart(listener: ChatTransportListener, signal?: AbortSignal): Promise<void>;\n\tstop(): Promise<void>;\n}\n\nexport interface TranscriptEntry {\n\tid: string;\n\tauthor: \"local\" | \"remote\";\n\tlabel: string;\n\tpublicKey: string;\n\ttext: string;\n\tsentAt: number;\n\tdelivery?: \"relayed\" | \"not-relayed\";\n\trelayedTo?: number;\n}\n\nexport interface ParticipantSnapshot {\n\tpublicKey: string;\n\tlabel: string;\n\tnickname: string;\n\tmuted: boolean;\n}\n\nexport interface ChatSnapshot {\n\tstate: \"connecting\" | \"connected\" | \"degraded\" | \"disconnected\";\n\troom: RoomDescriptor;\n\tlocalLabel: string;\n\tparticipants: ParticipantSnapshot[];\n\tdirectNeighbors: number;\n\tparticipantCatalogFull: boolean;\n\ttranscript: TranscriptEntry[];\n\tunread: number;\n\tcomposerOpen: boolean;\n\tlastError?: string;\n}\n\nexport interface ChatSessionOptions {\n\troom: RoomDescriptor;\n\tidentity: ChatIdentity;\n\tnickname: string;\n\ttransport: ChatTransport;\n\tnow?: () => number;\n\tonChange?: (snapshot: ChatSnapshot) => void;\n}\n\ninterface PeerState {\n\tpeer: TransportPeer;\n\tauthenticated: boolean;\n\tnickname?: string;\n\tviolations: number;\n\tlimiter: PeerRateLimiter;\n}\n\ninterface ParticipantState {\n\tpublicKey: Buffer;\n\tnickname: string;\n\tmuted: boolean;\n\tlastSeen: number;\n}\n\ninterface OriginLimiterState {\n\tlimiter: PeerRateLimiter;\n\tlastSeen: number;\n}\n\ninterface ParticipantVersionState {\n\tissuedAt: number;\n\tid: string;\n}\n\nexport class ChatSession {\n\tprivate readonly room: RoomDescriptor;\n\tprivate readonly identity: ChatIdentity;\n\tprivate nickname: string;\n\tprivate readonly transport: ChatTransport;\n\tprivate readonly now: () => number;\n\tprivate readonly onChange?: (snapshot: ChatSnapshot) => void;\n\tprivate readonly peers = new Map<string, PeerState>();\n\tprivate readonly participants = new Map<string, ParticipantState>();\n\tprivate readonly mutedOrigins = new Set<string>();\n\tprivate readonly transcript: TranscriptEntry[] = [];\n\tprivate readonly seen = new Map<string, number>();\n\tprivate readonly seenOrder: Array<{ key: string; expiresAt: number }> = [];\n\tprivate readonly originLimiters = new Map<string, OriginLimiterState>();\n\tprivate readonly participantVersions = new Map<string, ParticipantVersionState>();\n\tprivate readonly listeners = new Set<(snapshot: ChatSnapshot) => void>();\n\tprivate state: ChatSnapshot[\"state\"] = \"disconnected\";\n\tprivate unread = 0;\n\tprivate viewOpen = false;\n\tprivate lastError: string | undefined;\n\tprivate generation = 0;\n\tprivate leavePromise: Promise<void> | undefined;\n\tprivate heartbeatTimer: NodeJS.Timeout | undefined;\n\tprivate currentPresence: PresenceEvent | undefined;\n\tprivate participantCatalogFull = false;\n\n\tconstructor(options: ChatSessionOptions) {\n\t\tconst nickname = normalizeNickname(options.nickname);\n\t\tif (!nickname) throw new Error(\"Pi Chat nickname is invalid.\");\n\t\tthis.room = options.room;\n\t\tthis.identity = options.identity;\n\t\tthis.nickname = nickname;\n\t\tthis.transport = options.transport;\n\t\tthis.now = options.now ?? Date.now;\n\t\tthis.onChange = options.onChange;\n\t}\n\n\tasync start(signal?: AbortSignal): Promise<void> {\n\t\tif (this.state !== \"disconnected\" || this.leavePromise) {\n\t\t\tthrow new Error(\"Pi Chat session has already started.\");\n\t\t}\n\t\tconst owner = ++this.generation;\n\t\tthis.state = \"connecting\";\n\t\tthis.emit();\n\t\ttry {\n\t\t\tawait this.transport.start(\n\t\t\t\t{\n\t\t\t\t\tonPeer: (peer) => this.onPeer(owner, peer),\n\t\t\t\t\tonMessage: (peer, message) => this.onMessage(owner, peer, message),\n\t\t\t\t\tonDisconnect: (peer) => this.onDisconnect(owner, peer),\n\t\t\t\t\tonError: (error) => this.onError(owner, error),\n\t\t\t\t},\n\t\t\t\tsignal,\n\t\t\t);\n\t\t\tsignal?.throwIfAborted();\n\t\t\tif (owner !== this.generation) return;\n\t\t\tthis.state = \"connected\";\n\t\t\tthis.startHeartbeat(owner);\n\t\t\tthis.emit();\n\t\t} catch (error) {\n\t\t\tif (owner === this.generation) {\n\t\t\t\tthis.state = \"disconnected\";\n\t\t\t\tthis.lastError = safeError(error);\n\t\t\t\tthis.emit();\n\t\t\t}\n\t\t\tawait this.transport.stop().catch(() => undefined);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tsend(text: string): { id: string; relayedTo: number } {\n\t\tif (this.state !== \"connected\" && this.state !== \"degraded\") {\n\t\t\tthrow new Error(\"Pi Chat is not connected.\");\n\t\t}\n\t\tconst id = randomUUID();\n\t\tconst event = createChatEvent(this.room, this.identity, this.nickname, text, this.now(), id);\n\t\tthis.remember(eventKey(event));\n\t\tconst relayedTo = this.broadcast(createGossipMessage(event));\n\t\tthis.pushTranscript({\n\t\t\tid,\n\t\t\tauthor: \"local\",\n\t\t\tlabel: formatIdentityLabel(this.nickname, this.identity.publicKey),\n\t\t\tpublicKey: this.identity.publicKey.toString(\"hex\"),\n\t\t\ttext,\n\t\t\tsentAt: event.issuedAt,\n\t\t\tdelivery: relayedTo > 0 ? \"relayed\" : \"not-relayed\",\n\t\t\trelayedTo,\n\t\t});\n\t\tthis.emit();\n\t\treturn { id, relayedTo };\n\t}\n\n\tupdateNickname(value: string): void {\n\t\tconst nickname = normalizeNickname(value);\n\t\tif (!nickname) throw new Error(\"Pi Chat nickname is invalid.\");\n\t\tthis.nickname = nickname;\n\t\tthis.publishPresence(\"online\");\n\t\tthis.emit();\n\t}\n\n\tmute(publicKey: Uint8Array): void {\n\t\tconst id = keyId(publicKey);\n\t\tif (!this.participants.has(id)) return;\n\t\tthis.mutedOrigins.add(id);\n\t\tconst participant = this.participants.get(id);\n\t\tif (participant) participant.muted = true;\n\t\tthis.emit();\n\t}\n\n\ttoggleMute(publicKey: Uint8Array): boolean | undefined {\n\t\tconst id = keyId(publicKey);\n\t\tconst participant = this.participants.get(id);\n\t\tif (!participant) return undefined;\n\t\tif (this.mutedOrigins.has(id)) {\n\t\t\tthis.mutedOrigins.delete(id);\n\t\t\tparticipant.muted = false;\n\t\t} else {\n\t\t\tthis.mutedOrigins.add(id);\n\t\t\tparticipant.muted = true;\n\t\t}\n\t\tthis.emit();\n\t\treturn participant.muted;\n\t}\n\n\tsubscribe(listener: (snapshot: ChatSnapshot) => void): () => void {\n\t\tthis.listeners.add(listener);\n\t\treturn () => this.listeners.delete(listener);\n\t}\n\n\tsetViewOpen(open: boolean): void {\n\t\tif (this.viewOpen === open) return;\n\t\tthis.viewOpen = open;\n\t\tif (open) this.unread = 0;\n\t\tthis.emit();\n\t}\n\n\tleave(): Promise<void> {\n\t\tif (this.leavePromise) return this.leavePromise;\n\t\tthis.leavePromise = this.leaveOwned();\n\t\treturn this.leavePromise;\n\t}\n\n\tsnapshot(): ChatSnapshot {\n\t\tthis.pruneParticipants();\n\t\tconst active = [...this.participants.entries()];\n\t\tconst tags = uniqueIdentityTags([\n\t\t\tthis.identity.publicKey,\n\t\t\t...active.map(([, value]) => value.publicKey),\n\t\t]);\n\t\tconst localKey = this.identity.publicKey.toString(\"hex\");\n\t\tconst participants = active\n\t\t\t.map(([publicKey, value]) => ({\n\t\t\t\tpublicKey,\n\t\t\t\tnickname: value.nickname,\n\t\t\t\tlabel: `${value.nickname}~${tags.get(publicKey) ?? formatIdentityLabel(value.nickname, value.publicKey).split(\"~\").at(-1)}`,\n\t\t\t\tmuted: value.muted,\n\t\t\t}))\n\t\t\t.sort((left, right) => left.label.localeCompare(right.label));\n\t\treturn {\n\t\t\tstate: this.state,\n\t\t\troom: this.room,\n\t\t\tlocalLabel: `${this.nickname}~${tags.get(localKey) ?? formatIdentityLabel(this.nickname, this.identity.publicKey).split(\"~\").at(-1)}`,\n\t\t\tparticipants,\n\t\t\tdirectNeighbors: [...this.peers.values()].filter(({ authenticated }) => authenticated).length,\n\t\t\tparticipantCatalogFull: this.participantCatalogFull,\n\t\t\ttranscript: this.transcript.map((entry) => {\n\t\t\t\tconst tag = tags.get(entry.publicKey);\n\t\t\t\tconst nickname = entry.label.split(\"~\", 1)[0] ?? entry.label;\n\t\t\t\treturn { ...entry, label: tag ? `${nickname}~${tag}` : entry.label };\n\t\t\t}),\n\t\t\tunread: this.unread,\n\t\t\tcomposerOpen: this.viewOpen,\n\t\t\t...(this.lastError ? { lastError: this.lastError } : {}),\n\t\t};\n\t}\n\n\tprivate onPeer(owner: number, peer: TransportPeer): void {\n\t\tif (owner !== this.generation || this.state === \"disconnected\") {\n\t\t\tpeer.close();\n\t\t\treturn;\n\t\t}\n\t\tconst id = keyId(peer.publicKey);\n\t\tif (id === this.identity.publicKey.toString(\"hex\")) {\n\t\t\tpeer.close();\n\t\t\treturn;\n\t\t}\n\t\tconst previous = this.peers.get(id);\n\t\tif (previous && previous.peer !== peer) previous.peer.close();\n\t\tconst state: PeerState = {\n\t\t\tpeer,\n\t\t\tauthenticated: false,\n\t\t\tnickname: previous?.nickname,\n\t\t\tviolations: 0,\n\t\t\tlimiter: new PeerRateLimiter({ burst: 12, refillPerSecond: 4, now: this.now }),\n\t\t};\n\t\tthis.peers.set(id, state);\n\t\ttry {\n\t\t\tpeer.send(\n\t\t\t\tcreateHello(\n\t\t\t\t\tthis.room,\n\t\t\t\t\tthis.nickname,\n\t\t\t\t\tthis.identity.publicKey,\n\t\t\t\t\tpeer.publicKey,\n\t\t\t\t\trandomBytes(16),\n\t\t\t\t),\n\t\t\t);\n\t\t} catch {\n\t\t\tpeer.close();\n\t\t\tthis.peers.delete(id);\n\t\t}\n\t}\n\n\tprivate onMessage(owner: number, peer: TransportPeer, message: ProtocolMessage): void {\n\t\tif (owner !== this.generation) return;\n\t\tconst id = keyId(peer.publicKey);\n\t\tconst state = this.peers.get(id);\n\t\tif (!state || state.peer !== peer) return;\n\t\tif (!state.authenticated) {\n\t\t\tconst hello = verifyHello(message, this.room, peer.publicKey, this.identity.publicKey);\n\t\t\tif (!hello) {\n\t\t\t\tthis.violate(id, state);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tstate.authenticated = true;\n\t\t\tstate.nickname = hello.nickname;\n\t\t\tthis.upsertParticipant(id, peer.publicKey, hello.nickname, this.now());\n\t\t\tthis.sendPresenceTo(state.peer);\n\t\t\tthis.emit();\n\t\t\treturn;\n\t\t}\n\t\tif (message.type === \"hello\") return;\n\t\tif (message.type === \"goodbye\") {\n\t\t\tthis.peers.delete(id);\n\t\t\tpeer.close();\n\t\t\tthis.emit();\n\t\t\treturn;\n\t\t}\n\t\tif (message.type !== \"gossip\") {\n\t\t\tthis.violate(id, state);\n\t\t\treturn;\n\t\t}\n\t\tthis.onGossip(id, state, message);\n\t}\n\n\tprivate onGossip(peerId: string, state: PeerState, message: GossipMessage): void {\n\t\tconst event = message.event;\n\t\tconst key = eventKey(event);\n\t\tif (event.origin === this.identity.publicKey.toString(\"hex\") || this.hasSeen(key)) return;\n\t\tif (!state.limiter.accept()) {\n\t\t\tthis.violate(peerId, state);\n\t\t\treturn;\n\t\t}\n\t\tif (!verifyRoomEvent(event, this.room, this.now())) {\n\t\t\tthis.violate(peerId, state);\n\t\t\treturn;\n\t\t}\n\t\tif (!this.acceptOrigin(event.origin)) return;\n\t\tthis.remember(key);\n\t\tif (!this.applyEvent(event)) return;\n\t\tif (message.hops > 1) {\n\t\t\tthis.broadcast(createGossipMessage(event, message.hops - 1), state.peer);\n\t\t}\n\t}\n\n\tprivate applyEvent(event: RoomEvent): boolean {\n\t\tconst publicKey = Buffer.from(event.origin, \"hex\");\n\t\tconst participantStateIsNew = this.acceptParticipantVersion(event);\n\t\tif (event.kind === \"presence\") {\n\t\t\tif (!participantStateIsNew) return false;\n\t\t\tif (event.status === \"leaving\") {\n\t\t\t\tthis.participants.delete(event.origin);\n\t\t\t\tthis.originLimiters.delete(event.origin);\n\t\t\t} else {\n\t\t\t\tthis.upsertParticipant(event.origin, publicKey, event.nickname, this.now());\n\t\t\t}\n\t\t\tthis.emit();\n\t\t\treturn true;\n\t\t}\n\t\tif (participantStateIsNew) {\n\t\t\tthis.upsertParticipant(event.origin, publicKey, event.nickname, this.now());\n\t\t}\n\t\tif (!this.mutedOrigins.has(event.origin)) {\n\t\t\tthis.pushTranscript({\n\t\t\t\tid: event.id,\n\t\t\t\tauthor: \"remote\",\n\t\t\t\tlabel: formatIdentityLabel(event.nickname, publicKey),\n\t\t\t\tpublicKey: event.origin,\n\t\t\t\ttext: event.text,\n\t\t\t\tsentAt: event.issuedAt,\n\t\t\t});\n\t\t\tif (!this.viewOpen) this.unread += 1;\n\t\t}\n\t\tthis.emit();\n\t\treturn true;\n\t}\n\n\tprivate acceptParticipantVersion(event: RoomEvent): boolean {\n\t\tthis.pruneParticipantVersions();\n\t\tconst existing = this.participantVersions.get(event.origin);\n\t\tif (existing && compareEventVersion(existing, event) >= 0) return false;\n\t\tif (!existing && this.participantVersions.size >= MAX_SEEN_MESSAGES) {\n\t\t\tlet oldestOrigin: string | undefined;\n\t\t\tlet oldestVersion: ParticipantVersionState | undefined;\n\t\t\tfor (const [origin, candidate] of this.participantVersions) {\n\t\t\t\tif (!oldestVersion || compareEventVersion(candidate, oldestVersion) < 0) {\n\t\t\t\t\toldestOrigin = origin;\n\t\t\t\t\toldestVersion = candidate;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (oldestOrigin) this.participantVersions.delete(oldestOrigin);\n\t\t}\n\t\tthis.participantVersions.set(event.origin, {\n\t\t\tissuedAt: event.issuedAt,\n\t\t\tid: event.id,\n\t\t});\n\t\treturn true;\n\t}\n\n\tprivate pruneParticipantVersions(): void {\n\t\tconst oldest = this.now() - MAX_EVENT_AGE_MS;\n\t\tfor (const [origin, version] of this.participantVersions) {\n\t\t\tif (version.issuedAt < oldest) this.participantVersions.delete(origin);\n\t\t}\n\t}\n\n\tprivate onDisconnect(owner: number, peer: TransportPeer): void {\n\t\tif (owner !== this.generation) return;\n\t\tconst id = keyId(peer.publicKey);\n\t\tif (this.peers.get(id)?.peer === peer) {\n\t\t\tthis.peers.delete(id);\n\t\t\tthis.emit();\n\t\t}\n\t}\n\n\tprivate onError(owner: number, error: Error): void {\n\t\tif (owner !== this.generation) return;\n\t\tthis.state = \"degraded\";\n\t\tthis.lastError = safeError(error);\n\t\tthis.emit();\n\t}\n\n\tprivate startHeartbeat(owner: number): void {\n\t\tthis.heartbeatTimer = setInterval(() => {\n\t\t\tif (owner !== this.generation || this.state === \"disconnected\") return;\n\t\t\tthis.publishPresence(\"online\");\n\t\t\tthis.pruneParticipants();\n\t\t\tthis.emit();\n\t\t}, PRESENCE_HEARTBEAT_MS);\n\t\tthis.heartbeatTimer.unref();\n\t}\n\n\tprivate publishPresence(status: \"online\" | \"leaving\"): void {\n\t\tconst event = this.newPresence(status);\n\t\tthis.broadcast(createGossipMessage(event));\n\t}\n\n\tprivate sendPresenceTo(peer: TransportPeer): void {\n\t\tconst event = this.currentPresence ?? this.newPresence(\"online\");\n\t\ttry {\n\t\t\tpeer.send(createGossipMessage(event));\n\t\t} catch {\n\t\t\t// The transport will publish disconnect state.\n\t\t}\n\t}\n\n\tprivate newPresence(status: \"online\" | \"leaving\"): PresenceEvent {\n\t\tconst event = createPresenceEvent(\n\t\t\tthis.room,\n\t\t\tthis.identity,\n\t\t\tthis.nickname,\n\t\t\tstatus,\n\t\t\tthis.now(),\n\t\t\trandomUUID(),\n\t\t);\n\t\tthis.currentPresence = status === \"online\" ? event : undefined;\n\t\tthis.remember(eventKey(event));\n\t\treturn event;\n\t}\n\n\tprivate broadcast(message: GossipMessage, exclude?: TransportPeer): number {\n\t\tlet relayedTo = 0;\n\t\tfor (const state of this.peers.values()) {\n\t\t\tif (!state.authenticated || state.peer === exclude) continue;\n\t\t\ttry {\n\t\t\t\tstate.peer.send(message);\n\t\t\t\trelayedTo += 1;\n\t\t\t} catch {\n\t\t\t\tstate.violations += 1;\n\t\t\t}\n\t\t}\n\t\treturn relayedTo;\n\t}\n\n\tprivate upsertParticipant(\n\t\tid: string,\n\t\tpublicKey: Buffer,\n\t\tnickname: string,\n\t\tlastSeen: number,\n\t): void {\n\t\tconst existing = this.participants.get(id);\n\t\tif (!existing && this.participants.size >= MAX_PARTICIPANTS) {\n\t\t\tthis.participantCatalogFull = true;\n\t\t\treturn;\n\t\t}\n\t\tthis.participants.set(id, {\n\t\t\tpublicKey: Buffer.from(publicKey),\n\t\t\tnickname,\n\t\t\tmuted: this.mutedOrigins.has(id),\n\t\t\tlastSeen,\n\t\t});\n\t}\n\n\tprivate pruneParticipants(): void {\n\t\tthis.pruneParticipantVersions();\n\t\tconst oldest = this.now() - PARTICIPANT_TTL_MS;\n\t\tfor (const [id, participant] of this.participants) {\n\t\t\tif (participant.lastSeen < oldest) {\n\t\t\t\tthis.participants.delete(id);\n\t\t\t\tthis.originLimiters.delete(id);\n\t\t\t}\n\t\t}\n\t\tif (this.participants.size < MAX_PARTICIPANTS) this.participantCatalogFull = false;\n\t}\n\n\tprivate acceptOrigin(origin: string): boolean {\n\t\tconst current = this.now();\n\t\tlet state = this.originLimiters.get(origin);\n\t\tif (!state) {\n\t\t\tif (this.originLimiters.size >= MAX_ORIGIN_LIMITERS) {\n\t\t\t\tlet oldestKey: string | undefined;\n\t\t\t\tlet oldest = Number.POSITIVE_INFINITY;\n\t\t\t\tfor (const [key, candidate] of this.originLimiters) {\n\t\t\t\t\tif (candidate.lastSeen < oldest) {\n\t\t\t\t\t\toldest = candidate.lastSeen;\n\t\t\t\t\t\toldestKey = key;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (oldestKey) this.originLimiters.delete(oldestKey);\n\t\t\t}\n\t\t\tstate = {\n\t\t\t\tlimiter: new PeerRateLimiter({ burst: 6, refillPerSecond: 1, now: this.now }),\n\t\t\t\tlastSeen: current,\n\t\t\t};\n\t\t\tthis.originLimiters.set(origin, state);\n\t\t}\n\t\tstate.lastSeen = current;\n\t\treturn state.limiter.accept();\n\t}\n\n\tprivate hasSeen(key: string): boolean {\n\t\tthis.pruneSeen();\n\t\treturn this.seen.has(key);\n\t}\n\n\tprivate remember(key: string): void {\n\t\tthis.pruneSeen();\n\t\tconst expiresAt = this.now() + SEEN_MESSAGE_TTL_MS;\n\t\tthis.seen.set(key, expiresAt);\n\t\tthis.seenOrder.push({ key, expiresAt });\n\t\twhile (this.seen.size > MAX_SEEN_MESSAGES) {\n\t\t\tconst removed = this.seenOrder.shift();\n\t\t\tif (removed && this.seen.get(removed.key) === removed.expiresAt) {\n\t\t\t\tthis.seen.delete(removed.key);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate pruneSeen(): void {\n\t\tconst current = this.now();\n\t\twhile (this.seenOrder[0] && this.seenOrder[0].expiresAt <= current) {\n\t\t\tconst removed = this.seenOrder.shift();\n\t\t\tif (removed && this.seen.get(removed.key) === removed.expiresAt) {\n\t\t\t\tthis.seen.delete(removed.key);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate violate(id: string, state: PeerState): void {\n\t\tstate.violations += 1;\n\t\tif (state.violations > MAX_PROTOCOL_VIOLATIONS) {\n\t\t\tstate.peer.close();\n\t\t\tthis.peers.delete(id);\n\t\t\tthis.emit();\n\t\t}\n\t}\n\n\tprivate pushTranscript(entry: TranscriptEntry): void {\n\t\tthis.transcript.push(entry);\n\t\tif (this.transcript.length > MAX_TRANSCRIPT) this.transcript.shift();\n\t}\n\n\tprivate async leaveOwned(): Promise<void> {\n\t\tthis.generation += 1;\n\t\tif (this.heartbeatTimer) clearInterval(this.heartbeatTimer);\n\t\tthis.heartbeatTimer = undefined;\n\t\tif (this.state !== \"disconnected\") this.publishPresence(\"leaving\");\n\t\tfor (const state of this.peers.values()) {\n\t\t\tif (state.authenticated) {\n\t\t\t\ttry {\n\t\t\t\t\tstate.peer.send({ v: 2, type: \"goodbye\" });\n\t\t\t\t} catch {\n\t\t\t\t\t// Best-effort departure notice.\n\t\t\t\t}\n\t\t\t}\n\t\t\tstate.peer.close();\n\t\t}\n\t\tthis.peers.clear();\n\t\tthis.participants.clear();\n\t\tthis.originLimiters.clear();\n\t\tthis.participantVersions.clear();\n\t\tthis.seen.clear();\n\t\tthis.seenOrder.length = 0;\n\t\tawait this.transport.stop().catch((error) => {\n\t\t\tthis.lastError = safeError(error);\n\t\t});\n\t\tthis.state = \"disconnected\";\n\t\tthis.unread = 0;\n\t\tthis.transcript.length = 0;\n\t\tthis.emit();\n\t}\n\n\tprivate emit(): void {\n\t\tconst snapshot = this.snapshot();\n\t\tthis.onChange?.(snapshot);\n\t\tfor (const listener of this.listeners) listener(snapshot);\n\t}\n}\n\nfunction eventKey(event: RoomEvent): string {\n\treturn `${event.origin}:${event.id}`;\n}\n\nfunction compareEventVersion(\n\tleft: Pick<RoomEvent, \"issuedAt\" | \"id\">,\n\tright: Pick<RoomEvent, \"issuedAt\" | \"id\">,\n): number {\n\treturn left.issuedAt - right.issuedAt || left.id.localeCompare(right.id);\n}\n\nfunction keyId(publicKey: Uint8Array): string {\n\treturn Buffer.from(publicKey).toString(\"hex\");\n}\n\nfunction safeError(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,eAAe,uBAAuB;;;ACA/C,SAAS,aAAa,kBAAkB;AAmBxC,IAAM,iBAAiB;AACvB,IAAM,oBAAoB;AAC1B,IAAM,sBAAsB,KAAK;AACjC,IAAM,0BAA0B;AAChC,IAAM,mBAAmB;AACzB,IAAM,qBAAqB;AAC3B,IAAM,wBAAwB;AAC9B,IAAM,sBAAsB;AAqFrB,I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AChD,YAAM,QAAQ,IAAI;AAClB,UAAI,UAAU,qBAAsB;AACpC,iBAAW,MAAM,IAAI,aAAa,6BAA6B,YAAY,CAAC;AAC5E,YAAM,qBAAqB,EAAE;AAC7B,YAAM,eAAe;AACrB,YAAM,gBAAgB;AACtB,YAAM,wBAAwB,KAAK,YAAY;AAC/C,UAAI,yBAAyB,SAAS,eAAe,mBAAoB;AACzE,cAAQ,GAAG;AACX,6BAAuB;AACvB,sBAAgB;AAAA,IACjB,CAAC;AAAA,EACF;AACD;AAEA,SAAS,aACR,KACA,SACA,OACO;AACP,MAAI;AACH,QAAI,GAAG,OAAO,mBAAmB,OAAO,GAAG,KAAK;AAAA,EACjD,QAAQ;AAAA,EAER;AACD;AAEA,eAAe,gBACd,MACA,WAC8B;AAC9B,MAAI;AACH,UAAM,SAAS,MAAM,KAAK;AAC1B,WAAO,UAAU,IAAI,SAAS;AAAA,EAC/B,SAAS,OAAO;AACf,QAAI,CAAC,UAAU,EAAG,QAAO;AACzB,UAAM;AAAA,EACP;AACD;AAEA,SAAS,mBAA2B,MAAoD;AACvF,MAAI;AACJ,SAAO,MAAM;AACZ,QAAI,CAAC,SAAS;AACb,gBAAU,KAAK,EAAE,MAAM,CAAC,UAAU;AACjC,kBAAU;AACV,cAAM;AAAA,MACP,CAAC;AAAA,IACF;AACA,WAAO;AAAA,EACR;AACD;AAEA,IAAO,kBAAQ,sBAAsB;",
|
|
6
6
|
"names": ["updateChatSettings"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@narumitw/pi-chat",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"description": "Peer-to-peer chat extension for Pi.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"private": false,
|
|
@@ -24,9 +24,6 @@
|
|
|
24
24
|
"./dist/index.ts"
|
|
25
25
|
]
|
|
26
26
|
},
|
|
27
|
-
"piExtension": {
|
|
28
|
-
"lifecycle": "experimental"
|
|
29
|
-
},
|
|
30
27
|
"scripts": {
|
|
31
28
|
"build": "node scripts/build-runtime.mjs",
|
|
32
29
|
"check": "npm run build && biome check . && npm run typecheck",
|
|
@@ -35,7 +32,7 @@
|
|
|
35
32
|
"typecheck": "tsc --noEmit"
|
|
36
33
|
},
|
|
37
34
|
"dependencies": {
|
|
38
|
-
"@narumitw/pi-tui-kit": "^0.
|
|
35
|
+
"@narumitw/pi-tui-kit": "^0.59.0",
|
|
39
36
|
"hyperdht": "6.33.2",
|
|
40
37
|
"hyperswarm": "4.17.0",
|
|
41
38
|
"sodium-universal": "5.0.1"
|
|
@@ -45,10 +42,10 @@
|
|
|
45
42
|
"@earendil-works/pi-tui": "*"
|
|
46
43
|
},
|
|
47
44
|
"devDependencies": {
|
|
48
|
-
"@biomejs/biome": "2.5.
|
|
49
|
-
"@earendil-works/pi-coding-agent": "0.84.
|
|
50
|
-
"@earendil-works/pi-tui": "0.84.
|
|
51
|
-
"@types/node": "26.
|
|
45
|
+
"@biomejs/biome": "2.5.11",
|
|
46
|
+
"@earendil-works/pi-coding-agent": "0.84.4",
|
|
47
|
+
"@earendil-works/pi-tui": "0.84.4",
|
|
48
|
+
"@types/node": "26.4.0",
|
|
52
49
|
"esbuild": "0.28.2",
|
|
53
50
|
"typescript": "7.0.2"
|
|
54
51
|
},
|
package/src/menu.ts
CHANGED
|
@@ -368,7 +368,7 @@ export function createChatMenu(source: ChatMenuSource) {
|
|
|
368
368
|
kind: "detail",
|
|
369
369
|
title: "Pi Chat help",
|
|
370
370
|
lines: [
|
|
371
|
-
"Pi Chat is
|
|
371
|
+
"Pi Chat is TUI-only.",
|
|
372
372
|
"Chat stays outside Pi sessions, prompts, model context, and repository files.",
|
|
373
373
|
"Private invites are bearer secrets. Public rooms are guessable.",
|
|
374
374
|
"Noise encrypts direct streams, but peers and DHT infrastructure may observe network metadata.",
|
|
@@ -505,7 +505,7 @@ function mainScreen(state: ChatMenuState) {
|
|
|
505
505
|
return {
|
|
506
506
|
kind: "actions" as const,
|
|
507
507
|
title: "Pi Chat · disconnected",
|
|
508
|
-
lines: ["
|
|
508
|
+
lines: ["Peer-to-peer chat whose messages never enter model context."],
|
|
509
509
|
items: [
|
|
510
510
|
{
|
|
511
511
|
id: "browse",
|
package/src/pi-chat.ts
CHANGED
|
@@ -29,8 +29,6 @@ import {
|
|
|
29
29
|
import { sanitizeSingleLine } from "./text.js";
|
|
30
30
|
|
|
31
31
|
const CHAT_UI_KEY = "chat";
|
|
32
|
-
const EXPERIMENTAL_WARNING =
|
|
33
|
-
"Pi Chat is experimental. Peer identity, networking, and interaction behavior may change.";
|
|
34
32
|
const USAGE = "Usage: /chat, /chat <pichat:v1-or-v2:invite>, or /chat #<public-slug>";
|
|
35
33
|
const PRIVATE_ROOM_OPTIONS = [
|
|
36
34
|
"Join and remember — Save the bearer invite privately and restore this room",
|
|
@@ -686,7 +684,7 @@ export function createPiChatExtension(
|
|
|
686
684
|
};
|
|
687
685
|
|
|
688
686
|
pi.registerCommand("chat", {
|
|
689
|
-
description: "Open
|
|
687
|
+
description: "Open peer-to-peer developer chat",
|
|
690
688
|
handler: async (args, ctx) => {
|
|
691
689
|
if (ctx.mode !== "tui") throw new Error("Pi Chat requires Pi TUI mode.");
|
|
692
690
|
const owner = ctx.sessionManager;
|
|
@@ -773,7 +771,6 @@ export function createPiChatExtension(
|
|
|
773
771
|
settings = {};
|
|
774
772
|
notifySafely(ctx, "Pi Chat settings are invalid; fix the file before saving.", "error");
|
|
775
773
|
}
|
|
776
|
-
if (ctx.hasUI) notifySafely(ctx, EXPERIMENTAL_WARNING, "warning");
|
|
777
774
|
if (settings.resume && ctx.mode === "tui") {
|
|
778
775
|
void trackTask(restoreRememberedRoom(ctx, ownerGeneration));
|
|
779
776
|
}
|