diff --git a/.env.example b/.env.example index e58a01d..0144c96 100644 --- a/.env.example +++ b/.env.example @@ -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) diff --git a/AGENTS.md b/AGENTS.md index 897d3ab..646a784 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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) @@ -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` | diff --git a/README.md b/README.md index 160b044..068808a 100644 --- a/README.md +++ b/README.md @@ -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` | diff --git a/src/bot/commands/sessions.ts b/src/bot/commands/sessions.ts index eb644ec..07652d7 100644 --- a/src/bot/commands/sessions.ts +++ b/src/bot/commands/sessions.ts @@ -36,7 +36,23 @@ export async function sessionsCommand(ctx: CommandContext) { logger.debug(`[Sessions] Session: ${session.title} | ${session.directory}`); }); - if (sessions.length === 0) { + let filteredSessions = sessions; + if (config.bot.hideSubsessions) { + 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; } @@ -44,7 +60,7 @@ export async function sessionsCommand(ctx: CommandContext) { 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(); diff --git a/src/config.ts b/src/config.ts index fb6145c..0efd49b 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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),