feat(cli): provide manual session UUID via command line arg#26060
feat(cli): provide manual session UUID via command line arg#26060cocosheng-g merged 12 commits intomainfrom
Conversation
|
Size Change: +1.99 kB (+0.01%) Total Size: 33.9 MB
ℹ️ View Unchanged
|
|
Warning Gemini encountered an error creating the summary. You can try again by commenting |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds a --session-id flag to the CLI for manual session UUID specification. It includes logic to prevent conflicts with the --resume flag and ensures that provided session IDs are unique. Review feedback highlights a critical path traversal vulnerability due to the lack of input sanitization for the session ID, recommending strict validation and the use of nargs: 1 for the CLI option.
|
From PR Review: feat(cli): provide manual session UUID via command line argNice work on implementing manual session IDs! This is a great addition for users who need predictable session tracking. Suggestions for Improvement:
Minor Observation:The logic in |
|
@devr0306 addressed all comments |
|
Suggestions from Thank you for the PR! This is a great addition that addresses #19602. The implementation and tests are solid. I have two suggestions to improve validation consistency and performance: 1. Consolidate Session ID ValidationCurrently, there are two different validation checks for the session ID:
We should consolidate this by moving the stricter regex check into the Suggested change in .option('session-id', {
type: 'string',
nargs: 1,
description: 'Start a new session with a manually provided UUID.',
coerce: (value: string): string => {
const trimmed = value.trim();
if (!trimmed) {
throw new Error('The --session-id option cannot be empty.');
}
if (!/^[a-zA-Z0-9-_]+$/.test(trimmed)) {
throw new Error(
'Invalid session ID "' +
trimmed +
'": Only alphanumeric characters, dashes, and underscores are allowed.',
);
}
return trimmed;
},
})(You can then remove the regex check from 2. Optimize Session Existence CheckIn const sessions = await sessionSelector.listSessions();
if (sessions.some((s) => s.id === sessionIdArg)) { ... }If a user has many past sessions, this can become slow. We can optimize this by checking for the specific file directly using Suggested change (adding to async sessionExists(id: string): Promise<boolean> {
const chatsDir = path.join(this.storage.getProjectTempDir(), 'chats');
const files = await fs.readdir(chatsDir).catch(() => []);
return files.some(file => file.startsWith(SESSION_FILE_PREFIX + id + '-'));
}Then update if (await sessionSelector.sessionExists(sessionIdArg)) {
coreEvents.emitFeedback(
'error',
`Error starting session: Session ID "${sessionIdArg}" already exists. Use --resume to resume it, or provide a different ID.`,
);Let me know if you have any questions! |
|
addressed all |
Fixes #19602
Allows users to manually provide a specific session UUID using the
--session-idCLI flag. If provided alongside--resume, an error is returned to prevent ambiguity. Ensures this ID takes priority when creating a new session.Testing
parseArgumentsinconfig.test.ts--resumeand--session-idare provided--session-idingemini.test.tsx--resumeand--session-id) are correctly identified and rejected.