Skip to content

Commit debabe9

Browse files
committed
Configure Serena MCP and memories
- Add Serena project memories and Trae MCP server config\n- Fix sample BotEngine config keys: ReplyMode/ExecutionMode
1 parent 12d6588 commit debabe9

10 files changed

Lines changed: 149 additions & 3 deletions

File tree

.serena/memories/conventions.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
- Commands:
2+
- Implement as classes inheriting `BotCommandController`.
3+
- Route by attributes on methods: `[Command]`, `[TextCommand]`, `[TypedCommand]`, `[UpdateCommand]`, `[InlineQuery]`, `[Callback]`, `[DefaultCommand]`.
4+
- Controllers are constructed via `ActivatorUtilities.CreateInstance`; constructor DI is supported.
5+
- Prefer using `Context` + controller helper wrappers (`SendMessage`, `AnswerCallbackQuery`, `AnswerInlineQuery`) instead of reaching into Telegram client directly.
6+
- Middleware:
7+
- Implement `IBeforeCommand` and call `next(commandContext)` to pass; skipping it cancels command invocation.
8+
- Implement `IAfterCommand` for post-invocation work.
9+
- Disable middleware by annotating the class with `[DisabledMiddleware]` or listing its class name in `BotEngine.DisabledMiddleware`.
10+
- Configuration:
11+
- Binding paths are `BotEngine` (`BotEngineConfig.ConfigPath`) and `BotEngine:Bot` (`BotTokenConfig.ConfigPath`).
12+
- Important pitfall: sample `appsettings.Development.json` uses `ReplyStrategy`/`ExecutionStrategy`, but the model properties are `ReplyMode`/`ExecutionMode`.
13+
- Routing behavior (non-obvious):
14+
- Message routing checks in order: `[Command]` -> `[TextCommand]` -> `[TypedCommand]` -> `[DefaultCommand]`.
15+
- Inline query fallback: if no command match, falls back to any `[InlineQuery]`.
16+
- Callback fallback: falls back to `[Callback]` with empty command.
17+
- `ComparisonMode` enum has more values than currently implemented in router’s `TextCommand` switch.

.serena/memories/core.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
- Repo: C#/.NET Telegram bot framework + sample host.
2+
- Solution: `ZiziBot.TelegramBot.sln` with 2 projects:
3+
- Framework: `ZiziBot.TelegramBot.Framework/` (routing, middleware pipeline, polling/webhook engines)
4+
- Sample: `ZiziBot.TelegramBot.Sample/` (ASP.NET Core minimal host using the framework)
5+
- Read these when working in each area:
6+
- Framework architecture + entrypoints: `mem:framework/core`
7+
- Sample host wiring + examples: `mem:sample/core`
8+
- Project-wide references:
9+
- Toolchain + deps: `mem:tech_stack`
10+
- Commands to build/run/pack: `mem:suggested_commands`
11+
- Codebase conventions/pitfalls: `mem:conventions`
12+
- “Done” checklist for tasks: `mem:task_completion`
13+
- Primary runtime invariants (framework):
14+
- `AddZiziBotTelegramBot()` does assembly scanning for controllers + middleware and selects engine based on `BotEngine.EngineMode`.
15+
- `UseZiziBotTelegramBot()` maps webhook endpoints (if `WebApplication`) and starts the selected `IBotEngine`.
16+
- Each update is processed in an async DI scope via `BotEngineHandler` -> `BotUpdateHandler`.
17+
- Docs artifact: `CODE_WIKI.md` at repo root (human-facing, comprehensive).

.serena/memories/framework/core.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Framework module: `ZiziBot.TelegramBot.Framework/`.
2+
3+
Entry points:
4+
- DI registration + engine selection: `Extensions/ClientExtension.AddZiziBotTelegramBot()`.
5+
- Host startup: `Extensions/ClientExtension.UseZiziBotTelegramBot()`.
6+
- Webhook mapping: `Extensions/EndpointExtension.StartWebhookModeInternal()` maps `/api/telegram-webhook/{botToken}`.
7+
8+
Core flow:
9+
- `IBotEngine` implementation produces updates:
10+
- Polling: `Engines/BotPollingEngine` uses `StartReceiving`.
11+
- Webhook: `Engines/BotWebhookEngine` calls `SetWebhook` to `{WebhookUrl}/api/telegram-webhook/{botToken}`.
12+
- Updates are processed via `Handlers/BotEngineHandler` which creates an async DI scope per update and delegates to `Handlers/BotUpdateHandler`.
13+
- `BotEngineConfig.ExecutionMode` controls await vs fire-and-forget update handling.
14+
15+
Routing + pipeline:
16+
- Router: `Handlers/BotUpdateHandler` matches methods by attributes and invokes them.
17+
- Before/after middleware resolved from DI (`IBeforeCommand`, `IAfterCommand`).
18+
- Context: `Models/CommandContext` provides strongly-typed accessors + Telegram response helpers.
19+
20+
Known limitation:
21+
- `BotWebhookEngine.Stop(...)` is not implemented (throws).
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Memory Maintenance
2+
3+
## Discovery Model
4+
5+
- Core principle: progressive discovery through references, building a graph of memories.
6+
- Initially, agents are provided with the list of all memories (names only).
7+
- Agents should read `mem:core` as the top-level entry point (graph root).
8+
This memory should contain references to other memories covering major project domains.
9+
The referenced memories shall, in turn, shall contain references to even more specific memories, and so on.
10+
The depth of the graph shall depend on the project complexity.
11+
- Use topics/folders to group related memories in order to make the content structure explicit.
12+
Folders can mirror project structure (e.g. modules like frontend/backend) or topics like debugging, architecture, etc.
13+
- Memory references must use a mem: prefix inside backticks, e.g. `mem:frontend/core`.
14+
The surrounding text should clearly indicate when to read the memory/which content to expect.
15+
The text should provide more precise guidance than the memory name alone,
16+
i.e. avoid a reference like "frontend debugging: `mem:frontend/debugging` and instead make clear which aspects of frontend debugging are covered.
17+
- Memories themselves should not contain information about when to read them; this is the responsibility of the referring memory.
18+
19+
## Style
20+
21+
Dense agent notes, not prose docs. Prefer invariants, terse bullets.
22+
Avoid obvious context, rationale, and examples unless they prevent likely mistakes.
23+
Keep guidance durable and generalizable, not task-local.
24+
25+
## Add/update threshold
26+
27+
Add or update memories only with stable, non-obvious project conventions that avoid complex rediscovery in the future.
28+
Do not add: quick-read facts; generic language/framework knowledge; one-off task notes; volatile line-level details; behavior likely to change soon.
29+
30+
## Maintenance Actions
31+
32+
- Renaming memories: References are updated automatically if handled via Serena's memory rename tool.
33+
- Checking for stale memories (e.g. after deletion): Call `serena memories check` for a report.

.serena/memories/sample/core.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Sample module: `ZiziBot.TelegramBot.Sample/` (ASP.NET Core minimal host).
2+
3+
Startup:
4+
- `Program.cs` wires logging (Serilog), then calls `AddZiziBotTelegramBot()` and `UseZiziBotTelegramBot()`.
5+
- Exposes `GET /` => `OK!`.
6+
7+
Examples:
8+
- Commands in `Commands/` show:
9+
- Message commands via `[Command]` and `[TextCommand]`.
10+
- Default command via `[DefaultCommand]`.
11+
- Inline queries via `[InlineQuery]`.
12+
- Callback queries via `[Callback]`.
13+
- Non-message events via `[TypedCommand]` and `[UpdateCommand]`.
14+
- Middleware in `Middlewares/` show `IBeforeCommand`/`IAfterCommand` and disabling via `[DisabledMiddleware]` and `BotEngine.DisabledMiddleware`.
15+
16+
Config:
17+
- `appsettings.Development.json` contains `BotEngine` section with `EngineMode`, `WebhookUrl`, `DisabledMiddleware`, and bot tokens (`Bot`).
18+
- Align `ReplyStrategy`/`ExecutionStrategy` keys to `ReplyMode`/`ExecutionMode` if you want binding to work automatically.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- Build (repo root): `dotnet build` (or `dotnet build -c Release`).
2+
- Run sample host:
3+
- `cd ZiziBot.TelegramBot.Sample`
4+
- `dotnet run`
5+
- Pack (NuGet package for framework, repo root): `dotnet pack -c Release`.
6+
- CI parity (publish workflow): `dotnet restore` -> `dotnet build -c Release` -> `dotnet pack -c Release`.
7+
- No test projects currently; if added later: `dotnet test` at repo root.
8+
- Troubleshooting SDK mismatch:
9+
- Ensure .NET 10 SDK installed for the sample (`net10.0`).
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
For typical code changes:
2+
- `dotnet build -c Release` at repo root.
3+
- If changes touch runtime behavior, run sample:
4+
- set valid tokens in `ZiziBot.TelegramBot.Sample/appsettings.Development.json`
5+
- `cd ZiziBot.TelegramBot.Sample && dotnet run`
6+
- No linters/formatters/test runners configured beyond `dotnet build` (no test projects in repo).

.serena/memories/tech_stack.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
- Language: C# (nullable enabled), modern syntax (primary constructors used in core handlers/engines).
2+
- Build: `dotnet` (solution file), multi-target framework library.
3+
- Target frameworks:
4+
- Framework: `net8.0;net9.0;net10.0` (`ZiziBot.TelegramBot.Framework.csproj`)
5+
- Sample: `net10.0` (`ZiziBot.TelegramBot.Sample.csproj`)
6+
- Hosting: ASP.NET Core (Minimal APIs), `Microsoft.AspNetCore.App` framework reference in library.
7+
- Telegram integration:
8+
- NuGet ref: `WTelegramBot` (code uses `Telegram.Bot.*` API surface).
9+
- DI scanning: `Scrutor` (registers `IBeforeCommand`/`IAfterCommand`).
10+
- IDs/tracing: `UUIDNext` for `CommandContext.SessionId`.
11+
- Logging:
12+
- Framework uses `Microsoft.Extensions.Logging` abstractions.
13+
- Sample config uses `Serilog.AspNetCore`.

.trae/mcp.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"mcpServers": {
3+
"serena": {
4+
"command": "serena",
5+
"args": [
6+
"start-mcp-server",
7+
"--context=copilot-cli",
8+
"--project=${workspaceFolder}"
9+
]
10+
}
11+
}
12+
}

ZiziBot.TelegramBot.Sample/appsettings.Development.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"BotEngine": {
99
"WebhookUrl": "https://your-webhook-url.my.id",
1010
"EngineMode": "Auto",
11-
"ReplyStrategy": "ReplyToSender",
12-
"ExecutionStrategy": "Background",
11+
"ReplyMode": "ReplyToSender",
12+
"ExecutionMode": "Background",
1313
"DisabledMiddleware": [
1414
"ClassNameOfMiddlewareHere",
1515
"SampleDisabledClassBeforeMiddleware"
@@ -25,4 +25,4 @@
2525
}
2626
]
2727
}
28-
}
28+
}

0 commit comments

Comments
 (0)