-
Notifications
You must be signed in to change notification settings - Fork 120
fix: replace chalk.yellow with theme-aware hex in session-directory warning #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LifeJiggy
wants to merge
2
commits into
MoonshotAI:main
Choose a base branch
from
LifeJiggy:fix/named-color-violation-tui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@moonshot-ai/kimi-code": patch | ||
| --- | ||
|
|
||
| Replace chalk named color with theme-aware hex in session-directory warning. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { readFileSync, readdirSync } from 'node:fs'; | ||
| import { join, relative } from 'node:path'; | ||
|
|
||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| const SRC_ROOT = join(__dirname, '..', '..', 'src'); | ||
|
|
||
| const NAMED_COLORS = [ | ||
| 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', | ||
| 'white', 'gray', 'grey', 'black', | ||
| 'blackBright', 'whiteBright', 'redBright', 'greenBright', | ||
| 'yellowBright', 'blueBright', 'magentaBright', 'cyanBright', | ||
| ]; | ||
|
|
||
| const CHALK_NAMED_PATTERN = new RegExp( | ||
| `chalk\\.(${NAMED_COLORS.join('|')})\\(`, | ||
| ); | ||
|
|
||
| function walk(dir: string, files: string[] = []): string[] { | ||
| try { | ||
| for (const entry of readdirSync(dir, { withFileTypes: true })) { | ||
| const p = join(dir, entry.name); | ||
| if (entry.isDirectory()) { | ||
| walk(p, files); | ||
| } else if (entry.name.endsWith('.ts') && !entry.name.endsWith('.test.ts') && !entry.name.endsWith('.spec.ts')) { | ||
| files.push(p); | ||
| } | ||
| } | ||
| } catch { /* skip */ } | ||
| return files; | ||
| } | ||
|
|
||
| describe('chalk named color guard', () => { | ||
| it('forbids chalk named colors in production source code', () => { | ||
| const offenders: { file: string; line: number; snippet: string }[] = []; | ||
| const files = walk(SRC_ROOT); | ||
| let inBlockComment = false; | ||
| for (const file of files) { | ||
| const content = readFileSync(file, 'utf8'); | ||
| const lines = content.split('\n'); | ||
| for (let i = 0; i < lines.length; i++) { | ||
| const line = lines[i] ?? ''; | ||
| const trimmed = line.trimStart(); | ||
|
|
||
| if (inBlockComment) { | ||
| if (trimmed.includes('*/')) inBlockComment = false; | ||
| continue; | ||
| } | ||
|
|
||
| if (trimmed.startsWith('/*')) { | ||
| if (!trimmed.includes('*/')) inBlockComment = true; | ||
| continue; | ||
| } | ||
|
|
||
| if (trimmed.startsWith('//') || trimmed.startsWith('*')) continue; | ||
|
|
||
| CHALK_NAMED_PATTERN.lastIndex = 0; | ||
| const m = CHALK_NAMED_PATTERN.exec(line); | ||
| if (m) { | ||
| offenders.push({ | ||
| file: relative(SRC_ROOT, file), | ||
| line: i + 1, | ||
| snippet: line.trim(), | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| expect( | ||
| offenders, | ||
| `Found chalk named color usages. Use chalk.hex(colors.<token>) or theme styles instead.\n` + | ||
| offenders.map((o) => ` ${o.file}:${String(o.line)} ${o.snippet}`).join('\n'), | ||
| ).toEqual([]); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
kimi -p -r <session>hits the wrong-directory path on a light/white terminal, this hard-coded dark-theme warning color has only about 2.1:1 contrast against white; the palette already useslightColors.warning(#92660A, about 5.1:1) for this case. Because print mode has no theme detection here, replacing ANSI yellow with the dark palette hex makes this warning difficult to read for light-terminal users instead of fixing the contrast problem.Useful? React with 👍 / 👎.