Skip to content

Add docsgpt-bot: config, agents, storage, runtime, Markdown - #2

Merged
dartpain merged 1 commit into
arc53:mainfrom
arc53-machine:docsgpt-bot-core
Oct 1, 2026
Merged

dartpain merged 1 commit into
arc53:mainfrom
arc53-machine:docsgpt-bot-core

Conversation

@arc53-machine

@arc53-machine arc53-machine commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Adds the second crate, docsgpt-bot: the platform-neutral half of the Telegram bot, generalized so the Slack v2 bot can use it. The answer loop itself (a Surface trait plus run_turn) comes in the next PR.

What's in it

  • config: AgentConfig, [storage] and [server] tables for each bot to embed in its own deny_unknown_fields config, ${VAR} / ${VAR:-default} expansion (reports every missing variable at once), load_toml, find_config, and agents_from_env for the single-bot API_KEY / API_KEY_<NAME> layout both existing bots use.
  • Agents: validation (lowercase unique names, non-empty keys, at most one default) and routing. A #name prefix wins, then the chat's active agent, then the default. An unknown #tag is an error only when the bot has several agents, so hashtags still work on single-agent bots.
  • storage:
    • Scope { bot, space, thread, namespace } uses strings, so Slack's channel and thread_ts and Telegram's numeric ids both fit. The key format matches Telegram v2's.
    • Conversations carry a turn counter. record_turn returns the answer's position, which is feedback's question_index; we chose to count turns in the bots rather than change DocsGPT, and Add the docsgpt crate: Rust client for the DocsGPT API #1 confirmed against a live server that positions are 0-based in ask order.
    • Also: chat state with an extra map, JSON records for platform-only state, and message refs, so a 👍 on an old message maps back to its conversation and position.
    • SQLite and memory backends run one shared contract suite. The SQLite backend opens Telegram v2 files and adds the turns column, so the Telegram bot can move over in place.
  • runtime:
    • ScopeLocks: one turn at a time per chat.
    • CancelRegistry: its guards unregister on drop, and re-registering a key is safe.
    • Shutdown: SIGINT/SIGTERM, then drains turns in progress within a grace period. The Telegram bot drops them.
  • markdown:
    • Fence-aware markdown_blocks / split_markdown / clamp_markdown. The Telegram bot's clamp_rich could cut inside a code block; that case has a regression test.
    • Also: strip_images, close_open_fence, render_table_monospace, clean_title.

MongoDB is not supported, as agreed for the Slack rewrite.

Verification

  • cargo test --workspace --all-features: 25 new tests (contract suite on both backends, SQLite reopen, Telegram v2 file upgrade, routing, config, locks, cancel guards, shutdown drain, Markdown splitting), plus Add the docsgpt crate: Rust client for the DocsGPT API #1's.
  • cargo clippy -D warnings, cargo doc -D warnings, the MSRV 1.88 check and cargo publish --workspace --dry-run all pass.

The platform-neutral half of the Telegram bot, generalized so the Slack
bot can share it.

- config: AgentConfig, [storage] and [server] tables, ${VAR}
  expansion, load_toml, the API_KEY / API_KEY_<NAME> layout.
- Agents: validation and #name / active / default routing.
- storage: string-keyed Scope, conversations with a turn counter for
  feedback's question_index, chat state, JSON records and message refs;
  SQLite and memory pass one contract suite. SQLite reads Telegram v2
  files and adds the turns column on first open.
- runtime: ScopeLocks, CancelRegistry with self-unregistering guards,
  Shutdown that drains turns in progress.
- markdown: fence-aware splitting and clamping (the Telegram bot could
  cut inside a code block), image extraction, monospace tables.
@arc53-machine
arc53-machine marked this pull request as ready for review October 1, 2026 19:34
@dartpain
dartpain merged commit 24624ff into arc53:main Oct 1, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants