Skip to content

Commit c0d50ec

Browse files
ralyodioclaude
andauthored
feat: IRC-style /names and /list in the web composer and qc (0.9.4, qc 0.8.1) (#319)
/names shows who is in the open chat (admins first with @, agents marked with a robot) and /list shows the chats you are in, groups first, with member counts. Both are answered on the device from the already-loaded chat list and never sent as messages. The web composer shows them in a dismissible notice; the qc TUI puts them in the transcript. The CLI gets qc names <chat> and qc list (alias of qc chats). /api/conversations/load now returns participants' account_type so agents can be marked. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b16e4b0 commit c0d50ec

8 files changed

Lines changed: 164 additions & 7 deletions

File tree

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "qryptchat-web",
33
"private": true,
4-
"version": "0.9.3",
4+
"version": "0.9.4",
55
"type": "module",
66
"bin": {
77
"qc": "./bin/qc.js",

‎packages/qryptchat/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@profullstack/qryptchat",
3-
"version": "0.8.0",
3+
"version": "0.8.1",
44
"description": "qc: qrypt.chat in your terminal. A full-screen end-to-end encrypted chat client (ML-KEM-1024), plus a scriptable CLI and an MCP server.",
55
"type": "module",
66
"bin": {

‎src/app/api/conversations/load/route.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const POST = withAuth(async ({ locals }) => {
4545
participants:conversation_participants(
4646
user_id,
4747
role,
48-
user:users!conversation_participants_user_id_fkey(id, username, display_name, avatar_url, is_online, last_seen)
48+
user:users!conversation_participants_user_id_fkey(id, username, display_name, avatar_url, is_online, last_seen, account_type)
4949
)
5050
`)
5151
.in('id', conversationIds)

‎src/cli/commands.js‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { em, fail, info, mark, ok, warn, who } from './style.js';
1111
import { notify } from './notify.js';
1212
import { parseVoiceArgs, runPairux, voiceLink, VOICE_HELP } from './voice.js';
1313
import { voiceMessage } from '../lib/chat/voice.js';
14+
import { namesLines } from '../lib/chat/irc.js';
1415
export { exitWhenFlushed } from './exit.js';
1516

1617
/** An error as qc prints it: the error icon and the message. */
@@ -29,7 +30,8 @@ Usage:
2930
qc profile [--emoji 🔭] [--pronouns she/her] [--website URL] [--bio TEXT]
3031
show or set your public profile (an empty value clears it);
3132
--openprofile prints it as OpenProfile.md
32-
qc chats [--archived] list your chats (archived ones only with --archived)
33+
qc chats [--archived] list your chats (archived ones only with --archived); qc list is the same
34+
qc names <chat> who is in a chat (@ = admin, 🤖 = agent), like IRC /names
3335
qc archive <chat> archive a chat for you (qc unarchive <chat> brings it back)
3436
qc voice [--send <chat>] a link to a fresh end-to-end encrypted PairUX voice room (no account
3537
needed to join); qc voice login|join|... runs the pairux CLI (qc voice help)
@@ -198,6 +200,7 @@ export async function main(argv, { version = '0.0.0' } = {}) {
198200
return;
199201
}
200202
case 'chats':
203+
case 'list':
201204
case 'ls': {
202205
const all = await (await client(flags)).conversations();
203206
const chats = all.filter((c) => !!c.is_archived === !!flags.archived);
@@ -214,6 +217,15 @@ export async function main(argv, { version = '0.0.0' } = {}) {
214217
if (flags.json) return json({ id: chat.id, archived: cmd === 'archive' });
215218
return out(ok(cmd === 'archive' ? `Archived ${chat.title}. qc chats --archived lists it; qc unarchive brings it back.` : `${chat.title} is back in your chats.`));
216219
}
220+
case 'names': {
221+
if (!rest[0]) throw new Error('Usage: qc names <chat>');
222+
const chat = findChat(await (await client(flags)).conversations(), rest[0]);
223+
if (flags.json) {
224+
return json((chat.participants || []).map((p) => ({ id: p.user_id, username: p.user?.username, display_name: p.user?.display_name, role: p.role, agent: p.user?.account_type === 'agent' })));
225+
}
226+
for (const line of namesLines(chat, chat.title)) out(line);
227+
return;
228+
}
217229
case 'read': {
218230
if (!rest[0]) throw new Error('Usage: qc read <chat> [-n 20]');
219231
const c = await client(flags);

‎src/cli/tui.js‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* Composer commands: /voice posts a fresh end-to-end encrypted PairUX room,
1616
* /archive and /unarchive file the open chat away, /archived flips the list
1717
* between your chats and the archived ones (also Ctrl+O; `a` in the list).
18+
* /names (who is here) and /list (your chats) answer IRC-style in the
19+
* transcript, shown only to you and never sent.
1820
* The chat list reloads every 15 s as well as on live events, so it never
1921
* goes stale if the events stream drops.
2022
*
@@ -28,6 +30,7 @@ import { join } from 'node:path';
2830
import { configDir } from './config.js';
2931
import { notify } from './notify.js';
3032
import { newVoiceRoomLink, parseSlashCommand, PAIRUX_URL, voiceMessage } from '../lib/chat/voice.js';
33+
import { listLines, namesLines } from '../lib/chat/irc.js';
3134
import { CHAT_LIST_EVENTS, MEMBERSHIP_EVENTS } from '../lib/chat/membership-events.js';
3235

3336
const SIDEBAR = 30;
@@ -66,7 +69,7 @@ export function chatsWithNews(prev, next) {
6669
}
6770

6871
/** Composer slash commands the TUI handles itself; anything else is sent as typed. */
69-
export const SLASH_COMMANDS = ['voice', 'archive', 'unarchive', 'archived'];
72+
export const SLASH_COMMANDS = ['voice', 'archive', 'unarchive', 'archived', 'names', 'list'];
7073

7174
const pad2 = (n) => String(n).padStart(2, '0');
7275
const timeOf = (iso) => {
@@ -305,7 +308,9 @@ export async function runTui(client, { initialChat } = {}) {
305308
async function loadMessages(id) {
306309
try {
307310
const { messages } = await client.messages(id, { limit: 100 });
308-
state.messages[id] = messages;
311+
// Local /names and /list answers stay put between reloads.
312+
const local = (state.messages[id] || []).filter((m) => m.local);
313+
state.messages[id] = local.length ? [...messages, ...local].sort((a, b) => String(a.at).localeCompare(String(b.at))) : messages;
309314
redraw();
310315
} catch (err) {
311316
note(`Could not load messages: ${err.message}`);
@@ -408,6 +413,14 @@ export async function runTui(client, { initialChat } = {}) {
408413
state.field = { value: '', cursor: 0 };
409414
if (cmd.name === 'archived') toggleArchivedView();
410415
else if (!active) note('Pick a chat first');
416+
else if (cmd.name === 'names' || cmd.name === 'list') {
417+
// IRC-style, answered from the loaded chat list and shown only here.
418+
const lines = cmd.name === 'names' ? namesLines(active, active.title) : listLines(state.conversations, (c) => c.title);
419+
const at = new Date().toISOString();
420+
const local = { id: `local-${Date.now()}`, senderId: 'qc', sender: `qc /${cmd.name}`, local: true, text: lines.join('\n'), at };
421+
state.messages[active.id] = [...(state.messages[active.id] || []), local];
422+
state.scrollBack = 0;
423+
}
411424
else if (cmd.name === 'voice') {
412425
// Made here (src/lib/chat/voice.js) and sent inside the encrypted message.
413426
const url = newVoiceRoomLink(process.env.PAIRUX_API_URL || PAIRUX_URL);

‎src/lib/chat/irc.js‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* IRC-style `/names` and `/list`, answered on this device and never sent.
3+
*
4+
* /names who is in the open chat (admins first, marked @; agents 🤖)
5+
* /list the chats you are in, with how many people each has
6+
*
7+
* Both read the conversation list the client already loaded
8+
* (/api/conversations/load), so they cost no request and reveal nothing the
9+
* user could not already see in the sidebar.
10+
*/
11+
12+
export const IRC_COMMANDS = ['names', 'list'];
13+
14+
const nameOf = (p) => {
15+
const u = p.user || p;
16+
return u.username || u.display_name || 'unknown';
17+
};
18+
19+
/** Lines for `/names` in one conversation. */
20+
export function namesLines(conversation, title = conversation?.name || 'this chat') {
21+
const people = [...(conversation?.participants || [])].sort(
22+
(a, b) => (b.role === 'admin') - (a.role === 'admin') || nameOf(a).localeCompare(nameOf(b))
23+
);
24+
const names = people.map((p) => {
25+
const u = p.user || p;
26+
const op = p.role === 'admin' ? '@' : p.role === 'moderator' ? '+' : '';
27+
const agent = u.account_type === 'agent' ? ' 🤖' : '';
28+
return `${op}${nameOf(p)}${agent}`;
29+
});
30+
const n = names.length;
31+
return [`${title}: ${n} ${n === 1 ? 'person' : 'people'}`, names.join(' ') || '(nobody)'];
32+
}
33+
34+
/**
35+
* Lines for `/list`: your chats, groups first. `titleOf` names a chat (the
36+
* other person for a direct chat); archived chats are counted, not listed.
37+
*/
38+
export function listLines(conversations, titleOf = (c) => c.name || 'Chat') {
39+
const live = (conversations || []).filter((c) => !c.is_archived);
40+
const rank = { group: 0, direct: 1, note_to_self: 2 };
41+
const sorted = [...live].sort((a, b) => (rank[a.type] ?? 1) - (rank[b.type] ?? 1) || titleOf(a).localeCompare(titleOf(b)));
42+
const lines = sorted.map((c) => {
43+
const n = c.participants?.length ?? 0;
44+
const kind = c.type === 'group' ? 'group' : c.type === 'note_to_self' ? 'note' : 'direct';
45+
return `${c.type === 'group' ? '#' : ' '}${titleOf(c)} ${n} ${n === 1 ? 'person' : 'people'} · ${kind}`;
46+
});
47+
const archived = (conversations || []).length - live.length;
48+
return [`${live.length} ${live.length === 1 ? 'chat' : 'chats'}${archived ? ` (+${archived} archived)` : ''}`, ...lines];
49+
}

‎src/lib/chat/irc.test.js‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { IRC_COMMANDS, listLines, namesLines } from './irc.js';
3+
import { parseSlashCommand } from './voice.js';
4+
5+
const agents = {
6+
id: 'g1',
7+
type: 'group',
8+
name: 'Agents',
9+
participants: [
10+
{ user_id: 'b', role: 'member', user: { username: 'riotcoder', account_type: 'agent' } },
11+
{ user_id: 'c', role: 'member', user: { username: 'cha0spunk', account_type: 'agent' } },
12+
{ user_id: 'a', role: 'admin', user: { username: 'chovy', account_type: 'user' } },
13+
],
14+
};
15+
16+
describe('IRC commands', () => {
17+
it('parses /names and /list but not other slash text', () => {
18+
expect(parseSlashCommand('/names', IRC_COMMANDS)).toEqual({ name: 'names', args: '' });
19+
expect(parseSlashCommand(' /list ', IRC_COMMANDS)).toEqual({ name: 'list', args: '' });
20+
expect(parseSlashCommand('/namesake', IRC_COMMANDS)).toBeNull();
21+
expect(parseSlashCommand('/usr/bin is a path', IRC_COMMANDS)).toBeNull();
22+
});
23+
24+
it('/names puts admins first with @ and marks agents', () => {
25+
expect(namesLines(agents)).toEqual(['Agents: 3 people', '@chovy cha0spunk 🤖 riotcoder 🤖']);
26+
});
27+
28+
it('/names counts one person', () => {
29+
expect(namesLines({ participants: [{ role: 'member', user: { username: 'me' } }] }, 'Note to self')[0]).toBe('Note to self: 1 person');
30+
});
31+
32+
it('/list shows groups first and counts archived chats', () => {
33+
const dm = { id: 'd', type: 'direct', participants: [{}, {}] };
34+
const old = { id: 'o', type: 'group', name: 'Old', is_archived: true, participants: [] };
35+
const titleOf = (c) => c.name || 'Anthony';
36+
expect(listLines([dm, agents, old], titleOf)).toEqual([
37+
'2 chats (+1 archived)',
38+
'#Agents 3 people · group',
39+
' Anthony 2 people · direct',
40+
]);
41+
});
42+
});

‎src/lib/components/chat/MessageInput.jsx‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import EmojiEditor from './EmojiEditor.jsx';
1111
import { snippet } from '@/lib/chat/reactions.js';
1212
import { newVoiceRoomLink, parseSlashCommand, voiceMessage } from '@/lib/chat/voice.js';
1313
import EmojiPicker, { Icon } from './EmojiPicker.jsx';
14+
import { IRC_COMMANDS, listLines, namesLines } from '@/lib/chat/irc.js';
1415

1516
const MAX_FILE_SIZE = 2 * 1024 * 1024 * 1024; // 2GB
1617
const BLOCKED_EXTENSIONS = ['.exe', '.bat', '.cmd', '.scr', '.vbs', '.js'];
@@ -45,14 +46,16 @@ export default function MessageInput({ conversationId, disabled = false }) {
4546
const [isUploadingFiles, setIsUploadingFiles] = useState(false);
4647
const [selectedFiles, setSelectedFiles] = useState([]);
4748
const [uploadError, setUploadError] = useState('');
49+
const [notice, setNotice] = useState(null);
4850
const [showEmoji, setShowEmoji] = useState(false);
4951
const editorRef = useRef(null);
5052
const fileInputRef = useRef(null);
5153
const typingTimeoutRef = useRef(null);
5254

5355
const user = useAuthStore((s) => s.user);
54-
const { sendMessage, setTyping, stopTyping, loadMessages, replyingTo, clearReplyingTo } = useChatStore(
56+
const { conversations, sendMessage, setTyping, stopTyping, loadMessages, replyingTo, clearReplyingTo } = useChatStore(
5557
useShallow((s) => ({
58+
conversations: s.conversations,
5659
sendMessage: s.sendMessage,
5760
setTyping: s.setTyping,
5861
stopTyping: s.stopTyping,
@@ -70,8 +73,31 @@ export default function MessageInput({ conversationId, disabled = false }) {
7073
// A reply belongs to one conversation; switching chats drops it.
7174
useEffect(() => {
7275
clearReplyingTo();
76+
setNotice(null);
7377
}, [conversationId]);
7478

79+
// A chat's name, or the other people in it for a direct chat.
80+
function titleOf(c) {
81+
if (c.name) return c.name;
82+
if (c.type === 'note_to_self') return 'Note to self';
83+
const others = (c.participants || [])
84+
.filter((p) => (p.user_id ?? p.id) !== user?.id)
85+
.map((p) => p.user?.display_name || p.user?.username)
86+
.filter(Boolean);
87+
return others.join(', ') || 'Chat';
88+
}
89+
90+
// IRC-style /names and /list: answered here from the loaded chat list, never sent.
91+
function runIrcCommand(cmd) {
92+
if (cmd.name === 'names') {
93+
const active = conversations.find((c) => c.id === conversationId);
94+
setNotice(active ? namesLines(active, titleOf(active)) : ['Pick a chat first']);
95+
} else {
96+
setNotice(listLines(conversations, titleOf));
97+
}
98+
setMessageText('');
99+
}
100+
75101
function handleChange(val) {
76102
setMessageText(val);
77103
if (conversationId && user?.id) {
@@ -186,6 +212,8 @@ export default function MessageInput({ conversationId, disabled = false }) {
186212
if (!conversationId || isSending || isUploadingFiles) return;
187213

188214
let content = messageText.trim();
215+
const irc = !selectedFiles.length && parseSlashCommand(content, IRC_COMMANDS);
216+
if (irc) return runIrcCommand(irc);
189217
// /voice: post a fresh end-to-end encrypted PairUX room and open it here.
190218
// window.open runs before any await so the popup blocker allows it.
191219
if (!selectedFiles.length && parseSlashCommand(content, ['voice'])) {
@@ -256,6 +284,15 @@ export default function MessageInput({ conversationId, disabled = false }) {
256284
<div className="message-input-container">
257285
{uploadError && <div className="encryption-error">{uploadError}</div>}
258286

287+
{notice && (
288+
<div className="irc-notice" role="status">
289+
<button className="irc-notice-close" onClick={() => setNotice(null)} aria-label="Close" title="Close">×</button>
290+
<div className="irc-notice-title">{notice[0]}</div>
291+
{notice.slice(1).map((line, i) => <div key={i}>{line}</div>)}
292+
<div className="irc-notice-hint">Only you see this.</div>
293+
</div>
294+
)}
295+
259296
{selectedFiles.length > 0 && (
260297
<div className="file-preview-list">
261298
{selectedFiles.map((file, i) => (
@@ -331,6 +368,10 @@ export default function MessageInput({ conversationId, disabled = false }) {
331368

332369
<style>{`
333370
.message-input-container { position: absolute; bottom: 0; left: 0; right: 0; padding: .75rem 1rem; background: var(--color-bg-primary); border-top: 1px solid var(--color-border-primary); z-index: 10; }
371+
.irc-notice { position: relative; font-family: var(--font-mono, ui-monospace, monospace); font-size: .8125rem; line-height: 1.5; margin-bottom: .5rem; padding: .5rem 2rem .5rem .75rem; background: var(--color-surface, rgba(127,127,127,.08)); border: 1px solid var(--color-border, rgba(127,127,127,.25)); border-radius: .375rem; max-height: 14rem; overflow: auto; white-space: pre-wrap; }
372+
.irc-notice-title { font-weight: 600; }
373+
.irc-notice-hint { opacity: .6; font-size: .75rem; margin-top: .25rem; }
374+
.irc-notice-close { position: absolute; top: .25rem; right: .5rem; background: none; border: 0; color: inherit; font-size: 1rem; cursor: pointer; opacity: .7; }
334375
.encryption-error { color: var(--color-error); font-size: .8125rem; margin-bottom: .5rem; padding: .5rem; background: rgba(239,68,68,.1); border-radius: .375rem; }
335376
.file-preview-list { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .5rem; }
336377
.file-chip { display: flex; align-items: center; gap: .4rem; max-width: 240px; padding: .35rem .5rem; background: var(--color-bg-tertiary); border: 1px solid var(--color-border-primary); border-radius: .5rem; font-size: .8125rem; color: var(--color-text-primary); }

0 commit comments

Comments
 (0)