From 13953d79aa7b7d6e4a3eda2675dc69eff2b7e33e Mon Sep 17 00:00:00 2001 From: Ross Hartmann Date: Sat, 17 Oct 2026 14:26:43 -0700 Subject: [PATCH 1/2] feat(mobile): typing status phases; scope typing by the reply tag (M-4017) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Read the optional typing status in kind:20002 content ({"v":1,"phase":...}) and show it in the typing slot: "Assistant is starting up…", "is warming up a session…", "is reconnecting…", "is working…", or "is typing…". Unknown or malformed payloads are plain typing; "idle" ends that sender's typing at once. - Key typing and the replies that clear it by the message they answer (the `reply` e-tag), matching desktop and the thread view, instead of the thread root. Nested-thread typing now shows in its own thread, and an agent's reply clears exactly the typing it ends. Tests updated and authored (channel_typing_provider_test.dart) for CI; not run on this host. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Ross Hartmann --- .../channels/channel_typing_indicator.dart | 2 +- .../channels/channel_typing_provider.dart | 50 +++++++++++++++- .../channel_typing_provider_test.dart | 58 +++++++++++++++++-- 3 files changed, 103 insertions(+), 7 deletions(-) diff --git a/mobile/lib/features/channels/channel_typing_indicator.dart b/mobile/lib/features/channels/channel_typing_indicator.dart index b893f01fb0f..29fae2f6cef 100644 --- a/mobile/lib/features/channels/channel_typing_indicator.dart +++ b/mobile/lib/features/channels/channel_typing_indicator.dart @@ -45,7 +45,7 @@ class ChannelTypingIndicator extends ConsumerWidget { for (final entry in entries) labels[entry.pubkey.toLowerCase()]!, ]; final text = switch (names.length) { - 1 => '${names[0]} is typing…', + 1 => '${names[0]} ${typingPhaseSentence(entries.first.phase)}', 2 => '${names[0]} and ${names[1]} are typing…', _ => '${names[0]} and ${names.length - 1} others are typing…', }; diff --git a/mobile/lib/features/channels/channel_typing_provider.dart b/mobile/lib/features/channels/channel_typing_provider.dart index 1d04360c08d..d9b0de95b48 100644 --- a/mobile/lib/features/channels/channel_typing_provider.dart +++ b/mobile/lib/features/channels/channel_typing_provider.dart @@ -1,10 +1,42 @@ import 'dart:async'; +import 'dart:convert'; import 'package:flutter/foundation.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import '../../shared/relay/relay.dart'; +/// Status an agent can attach to its typing pulse (`{"v":1,"phase":...}` +/// in the ephemeral kind:20002 content). Absent or unknown means plain +/// "is typing…"; `idle` ends the sender's typing at once. +enum TypingPhase { starting, warming, reconnecting, working, typing, idle } + +/// Parses a typing pulse's optional status payload. +TypingPhase? parseTypingPhase(String content) { + if (content.isEmpty || content.length > 512) return null; + try { + final value = jsonDecode(content); + if (value is! Map || value['v'] != 1) return null; + final phase = value['phase']; + if (phase is! String) return null; + for (final candidate in TypingPhase.values) { + if (candidate.name == phase) return candidate; + } + } on FormatException { + return null; + } + return null; +} + +/// The status-line words after the sender's name, e.g. "is starting up…". +String typingPhaseSentence(TypingPhase? phase) => switch (phase) { + TypingPhase.starting => 'is starting up…', + TypingPhase.warming => 'is warming up a session…', + TypingPhase.reconnecting => 'is reconnecting…', + TypingPhase.working => 'is working…', + _ => 'is typing…', +}; + /// A single typing indicator entry. @immutable class TypingEntry { @@ -12,10 +44,14 @@ class TypingEntry { final String? threadHeadId; final int expiresAtMs; + /// The latest pulse's status; null is plain "is typing…". + final TypingPhase? phase; + const TypingEntry({ required this.pubkey, this.threadHeadId, required this.expiresAtMs, + this.phase, }); } @@ -131,14 +167,22 @@ class ChannelTypingNotifier extends Notifier> { final now = DateTime.now().millisecondsSinceEpoch; final at = event.createdAt * 1000; if (event.channelId != channelId || at > now || at + _ttlMs <= now) return; - final scope = (event.pubkey.toLowerCase(), event.threadReference.rootId); + // Typing and replies are scoped to the message they answer (the `reply` + // e-tag), exactly as desktop and the thread view key them. + final scope = (event.pubkey.toLowerCase(), event.threadReference.parentId); _activity.removeWhere((_, value) => value.retainUntil <= now); if (!_activity.containsKey(scope) && _activity.length >= 1024) return; final record = _activity.putIfAbsent(scope, _TypingActivity.new); if (event.kind == EventKind.typingIndicator) { if (at <= record.lastActivity || at <= record.lastMessage) return; record.lastActivity = at; - if (now >= record.quietUntil) record.visibleUntil = at + _ttlMs; + final phase = parseTypingPhase(event.content); + if (phase == TypingPhase.idle) { + record.visibleUntil = 0; + } else { + record.phase = phase; + if (now >= record.quietUntil) record.visibleUntil = at + _ttlMs; + } } else { if (at <= record.lastMessage) return; record.lastMessage = at; @@ -168,6 +212,7 @@ class ChannelTypingNotifier extends Notifier> { pubkey: entry.key.$1, threadHeadId: entry.key.$2, expiresAtMs: entry.value.visibleUntil, + phase: entry.value.phase, ), ]; if (_activity.isEmpty) { @@ -187,6 +232,7 @@ class _TypingActivity { int lastMessage = -1; int visibleUntil = 0; int quietUntil = 0; + TypingPhase? phase; int get retainUntil { final expiry = (lastActivity > lastMessage ? lastActivity : lastMessage) + 8000; diff --git a/mobile/test/features/channels/channel_typing_provider_test.dart b/mobile/test/features/channels/channel_typing_provider_test.dart index 53eacdbe0a3..f14e12e8626 100644 --- a/mobile/test/features/channels/channel_typing_provider_test.dart +++ b/mobile/test/features/channels/channel_typing_provider_test.dart @@ -165,9 +165,11 @@ void main() { container.read(provider); await Future.value(); final now = DateTime.now().millisecondsSinceEpoch ~/ 1000; - void emit(int kind, String agent, String root, int time) => relay.receive( + // Scope is the message the pulse or reply answers (its `reply` e-tag), + // as on desktop and in the thread view; the thread root does not split it. + void emit(int kind, String agent, String head, int time) => relay.receive( NostrEvent( - id: '$kind-$agent-$root-$time', + id: '$kind-$agent-$head-$time', pubkey: agent, kind: kind, createdAt: time, @@ -175,8 +177,8 @@ void main() { sig: '', tags: [ ['h', 'chat'], - ['e', root, '', 'root'], - ['e', threadIdParent, '', 'reply'], + ['e', threadIdParent, '', 'root'], + ['e', head, '', 'reply'], ], ), ); @@ -206,4 +208,52 @@ void main() { expect(container.read(provider), hasLength(2)); }, ); + test('typing status phases label the pulse; idle ends it at once', () async { + final relay = _Relay(); + final container = ProviderContainer( + overrides: [relaySessionProvider.overrideWith(() => relay)], + ); + addTearDown(container.dispose); + final provider = channelTypingProvider('chat'); + container.read(provider); + await Future.value(); + final now = DateTime.now().millisecondsSinceEpoch ~/ 1000; + void pulse(String content, int time) => relay.receive( + NostrEvent( + id: 'pulse-$time-${content.hashCode}', + pubkey: 'agent', + kind: 20002, + createdAt: time, + content: content, + sig: '', + tags: [ + ['h', 'chat'], + ], + ), + ); + pulse('{"v":1,"phase":"starting"}', now - 3); + expect(container.read(provider).single.phase, TypingPhase.starting); + pulse('{"v":1,"phase":"working"}', now - 2); + expect(container.read(provider).single.phase, TypingPhase.working); + pulse('{"v":1,"phase":"idle"}', now - 1); + expect(container.read(provider), isEmpty); + pulse('', now); + expect(container.read(provider).single.phase, isNull); + }); + + test('unknown or malformed status is plain typing', () { + expect(parseTypingPhase(''), isNull); + expect(parseTypingPhase('not json'), isNull); + expect(parseTypingPhase('{"v":2,"phase":"working"}'), isNull); + expect(parseTypingPhase('{"v":1,"phase":"dancing"}'), isNull); + expect(typingPhaseSentence(null), 'is typing…'); + expect(typingPhaseSentence(TypingPhase.starting), 'is starting up…'); + expect( + typingPhaseSentence(TypingPhase.warming), + 'is warming up a session…', + ); + expect(typingPhaseSentence(TypingPhase.reconnecting), 'is reconnecting…'); + expect(typingPhaseSentence(TypingPhase.working), 'is working…'); + expect(typingPhaseSentence(TypingPhase.typing), 'is typing…'); + }); } From 598c720ecafe827e8e3fb7ac5ee6cfe4d5c0b65d Mon Sep 17 00:00:00 2001 From: Ross Hartmann Date: Sat, 17 Oct 2026 21:12:07 -0700 Subject: [PATCH 2/2] docs(fork): inventory the mobile typing-phase delta (M-4017) Co-Authored-By: Claude Opus 5.5 Signed-off-by: Ross Hartmann --- docs/kiingo-fork-inventory.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/kiingo-fork-inventory.json b/docs/kiingo-fork-inventory.json index f456be9c8fa..834589b41fe 100644 --- a/docs/kiingo-fork-inventory.json +++ b/docs/kiingo-fork-inventory.json @@ -1547,6 +1547,18 @@ "purpose": "Typing status phases on desktop: reads the optional {\"v\":1,\"phase\":...} content of kind:20002 typing events and shows the sender's status line in the typing slot for DMs, channels and threads (starting up, warming up a session, reconnecting, working, typing). Unknown or malformed payloads stay plain typing, \"idle\" ends that sender's typing at once, and a reported phase wins over the local transcript headline in the bot activity row. Kiingo M-4017.", "removalCondition": "Drop when upstream reads typing status phases on desktop, or Kiingo agents stop sending phases.", "upstreamStatus": "Generic typing-status extension (backward-compatible content field); not yet submitted to block/buzz." + }, + { + "classification": "retain-generic", + "owner": "Buzz messaging maintainers", + "paths": [ + "mobile/lib/features/channels/channel_typing_indicator.dart", + "mobile/lib/features/channels/channel_typing_provider.dart", + "mobile/test/features/channels/channel_typing_provider_test.dart" + ], + "purpose": "Typing status phases on mobile: reads the optional {\"v\":1,\"phase\":...} content of kind:20002 typing events and shows the sender's status line (starting up, warming up a session, reconnecting, working, typing); unknown or malformed payloads stay plain typing and \"idle\" ends that sender's typing at once. Typing and the replies that clear it are keyed by the reply e-tag, matching desktop. Kiingo M-4017.", + "removalCondition": "Drop when upstream reads typing status phases and scopes mobile typing by the reply tag, or Kiingo agents stop sending phases.", + "upstreamStatus": "Generic typing-status extension (backward-compatible content field); not yet submitted to block/buzz." } ], "budgetAmendments": [