feat: add open command for opening directories as projects#70
feat: add open command for opening directories as projects#70paschdan wants to merge 4 commits intogrinev:mainfrom
Conversation
Extract the project-switching state logic (clear session, reset pinned message, refresh keyboard) from projects.ts into a shared utility so it can be reused by the upcoming /open command without duplication.
Add file-tree.ts with pure utilities for browsing the local filesystem: directory scanning with pagination, hidden-dir filtering, tilde-based display paths, entry labels, and tree headers with i18n-aware counts.
Add a new /open bot command that lets users browse the local filesystem via inline keyboard navigation and select a directory as a project. Includes callback-data path encoding to stay within Telegram's 64-byte limit, pagination, and i18n strings for all 6 supported locales.
|
@paschdan thanks for the PR! Only today I had time to look at it carefully and think about the feature as a whole. In general, I see the value of At the same time, in the current form I am a bit uncomfortable with this feature from a security point of view. Right now it allows browsing almost any local directory and selecting it as a project. That means the bot can be used not only for known project folders, but also for system folders or other sensitive locations on the machine. Even if the bot is limited to one Telegram user, this still feels too broad by default. I think this feature could work much better if we limit it to a configurable allowlist of roots. My suggestion:
For me this would be a much safer balance:
Below are also some technical remarks from the review:
Overall, I think the implementation work is solid, and I especially like the extraction of |
Description of changes
/opencommand: Adds a directory browser via Telegram inline keyboard, allowing users to navigate the local filesystem and select a folder as a project — without needing to know the exact path upfront.switchToProjectextraction: Refactors the project-switching state logic (clear session, reset pinned message, refresh keyboard) out ofprojects.tsinto a sharedsrc/bot/utils/switch-project.tsutility, eliminating duplication between/projectsand/open.file-treeutility: Addssrc/bot/utils/file-tree.tswith pure functions for directory scanning, pagination (8 entries/page), hidden-directory filtering, tilde-based display paths, and i18n-aware subfolder counts.callback_datalimit by transparently switching to compact indexed references (#0,#1, …) for long absolute paths.Closes issue (optional)
How it was tested
tests/bot/commands/open.test.ts— command, callback routing, busy guard, error paths, path encoding round-trips, stale index invalidationtests/bot/utils/switch-project.test.ts— all state-clearing branches, keyboard rebuild, pinned message failure resiliencetests/bot/utils/file-tree.test.ts— real temp-directory integration tests for scanning, pagination, hidden-dir filtering, error codesnpm run build— cleannpm run lint— cleannpm test— all passChecklist
feat: add /open command for browsing and adding project directoriesmainnpm run lint,npm run build, andnpm test