Skip to content

Commit c73df05

Browse files
committed
0.5.0: _
1 parent c26621b commit c73df05

17 files changed

Lines changed: 914 additions & 807 deletions

AGENTS.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
## 3. Project Topology
2424

2525
- `/index.ts`: Main extension entrypoint and runtime composition layer for the bridge
26-
- `/lib/*.ts`: Flat domain modules for reusable runtime logic. Favor domain files such as queueing/runtime, replies, polling, updates, attachments, registration/hooks, pi SDK adapter, Telegram API, config, turns, media, setup, rendering, menu/status/model-resolution support, and other cohesive bridge subsystems; use `shared` only when a type or constant truly spans multiple domains
26+
- `/lib/*.ts`: Flat domain modules for reusable runtime logic. Favor domain files such as queueing/runtime, replies, polling, updates, attachments, commands, lifecycle hooks, prompts, pi SDK adapter, Telegram API, config, turns, media, setup, rendering, menu/status/model-resolution support, and other cohesive bridge subsystems; use `shared` only when a type or constant truly spans multiple domains
2727
- `/tests/*.test.ts`: Domain-mirrored regression suites that follow the same flat naming as `/lib`
2828
- `/docs/README.md`: Documentation index for technical project docs
2929
- `/docs/architecture.md`: Runtime and subsystem overview for the bridge
@@ -95,10 +95,11 @@
9595
- Queue owns scheduling/lifecycle semantics: lane contracts, queue and active-turn stores, mutations, dispatch readiness/runtime, control/prompt enqueueing, session state appliers, and agent/tool lifecycle hooks; model owns model identity/thinking-level contracts, scoped resolution and CLI pattern parsing, current-model state/runtime helpers, in-flight switch state, restart eligibility, delayed abort decisions, Telegram-prefix-defaulted continuation prompt construction/queueing, and controller runtime binding over queue turns
9696
- Runtime owns session-local primitives and timers; locks owns shared `locks.json` singleton ownership, interactive takeover, stale same-`cwd` restart resume, session-replacement suspension, and ownership-drift shutdown; pi owns direct SDK imports and bound extension API ports; config owns persisted bot/session pairing state, single-user authorization, first-user pairing side effects, and inbound attachment handler config; API owns Bot API transport shapes/helpers, temp-dir/inbound-limit/runtime-error helpers, and runtime-bound chat actions
9797
- Preview owns streaming preview lifecycle and transports, defaulting reply metadata through the replies-domain helper when callers do not override it; replies owns final rendered-message delivery and reply parameters; rendering owns Telegram HTML Markdown/block/chunk/preview-snapshot formatting
98-
- Polling owns long-poll controller state/activity/loop wiring; updates owns callback/message/edit/reaction classification/execution; routing owns inbound update composition across menus, commands, media grouping, prompt queueing, edits, and paired authorization; handlers owns inbound attachment handler matching, command/tool invocation, prompt-text injection, and fallback behavior; registration owns pi tool/command/lifecycle-hook binding
99-
- Commands own slash-command parsing, execution-mode contracts, command target/control queue adapters, bot-command metadata/registration, and stop/compact/status/model/help side effects
98+
- Polling owns long-poll controller state/activity/loop wiring; updates owns callback/message/edit/reaction classification/execution; routing owns inbound update composition across menus, commands, media grouping, prompt queueing, edits, and paired authorization; handlers owns inbound attachment handler matching, command/tool invocation, prompt-text injection, and fallback behavior
99+
- Commands own Telegram slash-command parsing, execution-mode contracts, command target/control queue adapters, bot-command metadata/registration, pi `/telegram-*` command registration, and stop/compact/status/model/help side effects
100+
- Lifecycle owns pi lifecycle-hook binding; prompts owns Telegram-specific system prompt injection
100101
- Menu owns inline menu state/cache/building, callback/action runtimes, status/thinking/model UI support, and selection planning; status owns bridge status rendering, grouped pi-side diagnostic lines, and recent-event state
101-
- Turns own Telegram prompt turn-building/editing, prompt-prefix identity, and attachment-handler output handoff into prompt content; media owns inbound text/file/media-group extraction and download assembly; attachments own outbound file queueing, narrow structural attachment turn targets, stat checks, limits, and delivery classification; setup owns token prompt, env fallback, and validation flow
102+
- Turns own Telegram prompt turn-building/editing, prompt-prefix identity, and attachment-handler output handoff into prompt content; media owns inbound text/file/media-group extraction and download assembly; attachments own `telegram_attach` registration, outbound file queueing, narrow structural attachment turn targets, stat checks, limits, and delivery classification; setup owns token prompt, env fallback, and validation flow
102103

103104
## 6.4 Entrypoint And Import Boundaries
104105

BACKLOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@
22

33
## Active Backlog
44

5-
_No active backlog items._
5+
### Queue UX Improvement Pass
6+
7+
Improve the human-facing queue experience without broad architecture churn.
8+
9+
- Clarify queued, active, control, priority, dispatch-pending, compaction, and model-switch states in Telegram and pi-side status surfaces
10+
- Prefer local domain-owned formatting helpers; keep the `telegram_attach` spacing helper in `lib/attachments.ts`
11+
- Do not introduce a notification domain yet; consider one only after multiple Pi-facing notice/tool-result consumers need shared behavior
12+
- If queue complexity blocks UX work, extract narrow pure planning/state-machine helpers from `lib/queue.ts` instead of creating generic shared buckets
13+
- Watch for repeated structural contracts across domains and promote owner-domain exports only when duplication becomes real drift
14+
- Keep Telegram rendering helpers separate from Pi TUI/tool-result formatting
15+
- Sync `README.md`, `docs`, and `CHANGELOG.md` when user-visible queue behavior changes
16+
- Validate queue changes with the focused queue tests first, then the default regression suite when dispatch/lifecycle semantics change
617

718
## Reopen Triggers
819

docs/architecture.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Current runtime areas include:
2626
- Telegram Bot API concrete transport shapes live with Telegram API helpers in `/lib/api.ts`, while persisted bot/session pairing state lives in `/lib/config.ts`; domain-owned runtime state types stay with their owners, such as queued/active turn state in `/lib/queue.ts` and preview state in `/lib/preview.ts`, while domain helpers prefer local structural `*Like` contracts instead of importing concrete wire DTOs
2727
- Direct pi SDK imports are centralized in `/lib/pi.ts`, which exposes concrete pi SDK type exports, bound extension API runtime ports, and narrow bridge-facing helpers such as settings-manager creation plus context model/idle/pending-message/compaction adapters; `index.ts` uses this adapter namespace instead of importing `@mariozechner/pi-coding-agent` directly
2828
- Session-local runtime primitives such as queue/control/priority ordering counters, lifecycle/dispatch flags, setup guard state, abort-handler storage/binding, typing-loop timer lifecycle, typing-loop starter binding, prompt-dispatch lifecycle/runtime adapters, and agent-end reset sequencing in `/lib/runtime.ts`; the runtime domain's essence is mutable cross-domain session coordination rather than business behavior. It exposes a grouped bridge runtime facade with named queue/lifecycle/setup/abort/typing ports that bind those primitives to one session state while remaining a cohesive state/runtime boundary, and `index.ts` still wires live Telegram API calls and status updates into those helpers. Preview-specific state, draft-support detection, and draft-id allocation live in `/lib/preview.ts`.
29-
- Constants live in their owning domains instead of a shared constants module: API paths/inbound limits and inbound file-size env parsing in `/lib/api.ts`, outbound attachment limits and outbound attachment-size env parsing in `/lib/attachments.ts`, media-group debounce in `/lib/media.ts`, attachment-handler timeout and local tool lookup defaults in `/lib/handlers.ts`, menu cache/state bounds in `/lib/menu.ts`, preview throttle/draft bounds in `/lib/preview.ts`, typing cadence in `/lib/runtime.ts`, diagnostic ring limits in `/lib/status.ts`, Telegram prompt prefix in `/lib/turns.ts`, and system-prompt guidance in `/lib/registration.ts`.
29+
- Constants live in their owning domains instead of a shared constants module: API paths/inbound limits and inbound file-size env parsing in `/lib/api.ts`, outbound attachment limits and outbound attachment-size env parsing in `/lib/attachments.ts`, media-group debounce in `/lib/media.ts`, attachment-handler timeout and local tool lookup defaults in `/lib/handlers.ts`, menu cache/state bounds in `/lib/menu.ts`, preview throttle/draft bounds in `/lib/preview.ts`, typing cadence in `/lib/runtime.ts`, diagnostic ring limits in `/lib/status.ts`, Telegram prompt prefix in `/lib/turns.ts`, and system-prompt guidance in `/lib/prompts.ts`.
3030
- Queueing, narrow Telegram prompt content contracts, queue-store contracts/state helpers, active-turn state helpers, dispatch-readiness adapters, queue append/mutation runtime/controller adapters, control enqueue controllers, queue dispatch readiness/controller/runtime adapters, prompt enqueue/history planning/runtime/controllers, queue-runtime, session state appliers plus lifecycle/runtime sequencing, session start/shutdown sequencing plus hook binding, agent-start/agent-end lifecycle handling plus hook/runtime binding, and tool lifecycle handling plus tool-execution hook/runtime binding in `/lib/queue.ts`
3131
- Model identity/thinking-level contracts, scoped model-pattern parsing/resolution/sorting, current-model store/update/runtime helpers, in-flight model-switch state helpers, restart eligibility, delayed abort decisions, Telegram-prefix defaulted continuation prompt construction, continuation queue adapters, and model-switch controller/runtime binding over queue-owned turns in `/lib/model.ts`
3232
- Preview transport-selection, assistant-message preview lifecycle hook binding/handling, preview-finalization, preview controller state/reset helpers, preview Bot API message/rendered-chunk transport adapters, preview-controller/assistant-preview runtime binding, reply-metadata defaulting through the replies-domain helper, and preview-runtime helpers in `/lib/preview.ts`
@@ -38,11 +38,11 @@ Current runtime areas include:
3838
- Telegram turn-building helpers, runtime turn-builder wiring over media download ports and media-owned downloaded-file metadata contracts, inbound attachment handler processing, queued-prompt edit runtime binding, and Node-backed image-file reads for pi image inputs in `/lib/turns.ts`
3939
- Telegram media/text extraction, file-info normalization, downloaded-message-file metadata contracts, inbound file download assembly, media-group debounce helpers, media-group controller state, and media-group-aware authorized-message dispatch adapter wiring in `/lib/media.ts`
4040
- Telegram inbound attachment handler matching, command placeholder substitution, local tool invocation, handler-output collection, and quiet failure handling in `/lib/handlers.ts`
41-
- Telegram slash-command parsing, command-message target helpers/adapters, command control-enqueue adapters/runtime binding, command-action routing, command-handler/target-runtime and command-or-prompt dispatch binding, command runtime port orchestration, shared command-runtime reply/status/control adapter closures, stop/compact/status/model/help command side-effect branching, bound Bot API command registration, and Bot API command metadata helpers in `/lib/commands.ts`
41+
- Telegram slash-command parsing, command-message target helpers/adapters, command control-enqueue adapters/runtime binding, command-action routing, command-handler/target-runtime and command-or-prompt dispatch binding, command runtime port orchestration, shared command-runtime reply/status/control adapter closures, stop/compact/status/model/help command side-effect branching, bound Bot API command registration, Bot API command metadata helpers, and pi `/telegram-*` command registration in `/lib/commands.ts`
4242
- Telegram updates extraction, authorization classification, execution-planning, authorized reaction priority/removal handling, direct execute-from-update routing, and runtime helpers in `/lib/updates.ts`
4343
- Inbound route composition across paired update execution, callback menus, command-or-prompt dispatch, media grouping, prompt enqueueing, queued edits, and attachment-handler turn building in `/lib/routing.ts`
44-
- Telegram attachment queueing, narrow structural attachment turn targets, queued-attachment sender runtime binding, delivery helpers, Node-backed file stat checks, outbound photo-vs-document classification, and outbound attachment limits/env parsing in `/lib/attachments.ts`
45-
- Telegram tool, command, before-agent prompt, and lifecycle-hook registration helpers in `/lib/registration.ts`
44+
- Telegram attachment queueing, `telegram_attach` tool registration, narrow structural attachment turn targets, queued-attachment sender runtime binding, delivery helpers, Node-backed file stat checks, outbound photo-vs-document classification, and outbound attachment limits/env parsing in `/lib/attachments.ts`
45+
- Telegram-specific system prompt injection helpers in `/lib/prompts.ts`, and pi lifecycle-hook binding helpers in `/lib/lifecycle.ts`
4646
- Setup/token prompt, environment fallback, guarded setup runtime adapter wiring, structural setup config contract, token validation, config persistence orchestration, and setup notification helpers in `/lib/setup.ts`
4747
- Markdown block scanning/rendering, inline-token/style rendering, text-piece rendering, stable-preview block scanning, final rendered-block chunk balancing, preview-snapshot derivation, HTML escaping, raw HTML tag-preserving chunking, and Telegram message rendering helpers in `/lib/rendering.ts`
4848
- Status-bar rendering/runtime adapters, bridge status state adapters, status-message rendering and status-HTML binding, structural queue-lane status view contracts, structured redacted runtime-event recording, recent-event recorder state, recent-event line formatting, and grouped pi-side diagnostics helpers in `/lib/status.ts`

index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55

66
import * as Api from "./lib/api.ts";
77
import * as Attachments from "./lib/attachments.ts";
8+
import * as Commands from "./lib/commands.ts";
89
import * as Config from "./lib/config.ts";
910
import * as Handlers from "./lib/handlers.ts";
11+
import * as Lifecycle from "./lib/lifecycle.ts";
1012
import * as Locks from "./lib/locks.ts";
1113
import * as Media from "./lib/media.ts";
1214
import * as Menu from "./lib/menu.ts";
1315
import * as Model from "./lib/model.ts";
1416
import * as Pi from "./lib/pi.ts";
1517
import * as Polling from "./lib/polling.ts";
1618
import * as Preview from "./lib/preview.ts";
19+
import * as Prompts from "./lib/prompts.ts";
1720
import * as Queue from "./lib/queue.ts";
18-
import * as Registration from "./lib/registration.ts";
1921
import * as Replies from "./lib/replies.ts";
2022
import * as Runtime from "./lib/runtime.ts";
2123
import * as Routing from "./lib/routing.ts";
@@ -255,7 +257,7 @@ export default function (pi: Pi.ExtensionAPI) {
255257
updateStatus,
256258
recordRuntimeEvent: runtimeEvents.record,
257259
});
258-
const sessionLifecycleRuntime = Registration.appendTelegramLifecycleHooks(
260+
const sessionLifecycleRuntime = Lifecycle.appendTelegramLifecycleHooks(
259261
Queue.createTelegramSessionLifecycleRuntime<
260262
Pi.ExtensionContext,
261263
RuntimeTelegramQueueItem,
@@ -282,14 +284,14 @@ export default function (pi: Pi.ExtensionAPI) {
282284
{ onSessionStart: lockedPollingRuntime.onSessionStart },
283285
);
284286

285-
// --- Extension Registration ---
287+
// --- Extension API Bindings ---
286288

287-
Registration.registerTelegramAttachmentTool(pi, {
289+
Attachments.registerTelegramAttachmentTool(pi, {
288290
getActiveTurn: activeTurnRuntime.get,
289291
recordRuntimeEvent: runtimeEvents.record,
290292
});
291293

292-
Registration.registerTelegramCommands(pi, {
294+
Commands.registerTelegramBridgeCommands(pi, {
293295
promptForConfig: Setup.createTelegramSetupPromptRuntime({
294296
getConfig: configStore.get,
295297
setConfig: configStore.set,
@@ -310,9 +312,9 @@ export default function (pi: Pi.ExtensionAPI) {
310312

311313
// --- Lifecycle Hooks ---
312314

313-
Registration.registerTelegramLifecycleHooks(pi, {
315+
Lifecycle.registerTelegramLifecycleHooks(pi, {
314316
...sessionLifecycleRuntime,
315-
onBeforeAgentStart: Registration.createTelegramBeforeAgentStartHook(),
317+
onBeforeAgentStart: Prompts.createTelegramBeforeAgentStartHook(),
316318
onModelSelect: currentModelRuntime.onModelSelect,
317319
...Queue.createTelegramAgentLifecycleHooks<
318320
Queue.PendingTelegramTurn,

0 commit comments

Comments
 (0)