Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ OPENCODE_MODEL_ID=big-pickle
# SESSIONS_LIST_LIMIT=10
# Bot locale: en or ru (default: en)
# BOT_LOCALE=en
# Hide subsessions (child sessions) in /sessions list (default: false)
# Set to "true" to show only top-level sessions
# HIDE_SUBSESSIONS=false

# Code File Settings (optional)
# Maximum file size in KB to send as document (default: 100)
Expand Down
2 changes: 2 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ OPENCODE_MODEL_ID=big-pickle

# Bot options (optional)
# SESSIONS_LIST_LIMIT=10
# HIDE_SUBSESSIONS=false # Hide child sessions from /sessions list
# BOT_LOCALE=en # en or ru

# File output options (optional)
Expand All @@ -274,6 +275,7 @@ OPENCODE_MODEL_ID=big-pickle
| `OPENCODE_SERVER_PASSWORD` | OpenCode auth password | No | empty |
| `LOG_LEVEL` | Logging level | No | `info` |
| `SESSIONS_LIST_LIMIT` | Max sessions shown in `/sessions` | No | `10` |
| `HIDE_SUBSESSIONS` | Hide child sessions from list | No | `false` |
| `BOT_LOCALE` | Bot locale (`en` or `ru`) | No | `en` |
| `CODE_FILE_MAX_SIZE_KB` | Max code file size to send | No | `100` |

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ When installed via npm, the configuration wizard handles the initial setup. The
| `OPENCODE_MODEL_ID` | Default model ID | Yes | `big-pickle` |
| `BOT_LOCALE` | Bot UI language (`en` or `ru`) | No | `en` |
| `SESSIONS_LIST_LIMIT` | Max sessions shown in `/sessions` | No | `10` |
| `HIDE_SUBSESSIONS` | Hide child sessions from `/sessions` list | No | `false` |
| `CODE_FILE_MAX_SIZE_KB` | Max file size (KB) to send as document | No | `100` |
| `LOG_LEVEL` | Log level (`debug`, `info`, `warn`, `error`) | No | `info` |

Expand Down
20 changes: 18 additions & 2 deletions src/bot/commands/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,31 @@ export async function sessionsCommand(ctx: CommandContext<Context>) {
logger.debug(`[Sessions] Session: ${session.title} | ${session.directory}`);
});

if (sessions.length === 0) {
let filteredSessions = sessions;
if (config.bot.hideSubsessions) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, child sessions are filtered out after fetching a limited list (limit).
With HIDE_SUBSESSIONS=true, this can produce incomplete results (or even an empty list) if many recent items are subsessions, even when root sessions exist beyond the current page.
Could we pass "roots: true" to "session.list()" when this option is enabled, and keep client-side filtering only as a fallback?
That would preserve correct "/sessions" behavior with any limit.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes roots true would be enough here, imho

filteredSessions = sessions.filter((session) => {
const isSubsession = (session as { parentID?: string }).parentID != null;
if (isSubsession) {
logger.debug(
`[Sessions] Filtering out subsession: ${session.title} (parentID: ${(session as { parentID?: string }).parentID})`,
);
}
return !isSubsession;
});
logger.debug(
`[Sessions] Filtered ${sessions.length - filteredSessions.length} subsessions, showing ${filteredSessions.length} top-level sessions`,
);
}

if (filteredSessions.length === 0) {
await ctx.reply(t("sessions.empty"));
return;
}

const keyboard = new InlineKeyboard();
const localeForDate = getLocale() === "ru" ? "ru-RU" : "en-US";

sessions.forEach((session, index) => {
filteredSessions.forEach((session, index) => {
const date = new Date(session.time.created).toLocaleDateString(localeForDate);
const label = `${index + 1}. ${session.title} (${date})`;
keyboard.text(label, `session:${session.id}`).row();
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const config = {
bot: {
sessionsListLimit: getOptionalPositiveIntEnvVar("SESSIONS_LIST_LIMIT", 10),
locale: getOptionalLocaleEnvVar("BOT_LOCALE", "en"),
hideSubsessions: getEnvVar("HIDE_SUBSESSIONS", false) === "true",
},
files: {
maxFileSizeKb: parseInt(getEnvVar("CODE_FILE_MAX_SIZE_KB", false) || "100", 10),
Expand Down