mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-12 22:14:22 +00:00
refactor(cliproxy): address PR review suggestions
- Add hash collision risk note to sanitizer docs (6-char MD5 = ~16M combos) - Fix VALID_CHARS_REGEX comment to include '/' character - Use getCcsDir() instead of os.homedir() for log path (CLAUDE.md compliance) - Add JSDoc for isRecord type guard helper
This commit is contained in:
1 parent
4d292c62e4
commit
d86c53146a
2 files changed
+11
-4
No files matched your search
@@ -4,11 +4,14 @@
|
|||||||
* Sanitizes MCP tool names to comply with Gemini API constraints:
|
* Sanitizes MCP tool names to comply with Gemini API constraints:
|
||||||
* - Max 64 characters
|
* - Max 64 characters
|
||||||
* - Must start with letter or underscore
|
* - Must start with letter or underscore
|
||||||
* - Only a-z A-Z 0-9 _ . : - allowed
|
* - Only a-z A-Z 0-9 _ . : - / allowed
|
||||||
*
|
*
|
||||||
* Strategies:
|
* Strategies:
|
||||||
* 1. Remove duplicate segments (e.g., gitmcp__foo__foo → gitmcp__foo)
|
* 1. Remove duplicate segments (e.g., gitmcp__foo__foo → gitmcp__foo)
|
||||||
* 2. Smart truncate with hash suffix if still >64 chars
|
* 2. Smart truncate with hash suffix if still >64 chars
|
||||||
|
*
|
||||||
|
* Note: Hash collision risk is ~1 in 16M with 6-char MD5 prefix.
|
||||||
|
* Acceptable for typical MCP tool counts (<1000 tools).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { createHash } from 'crypto';
|
import { createHash } from 'crypto';
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ import * as http from 'http';
|
|||||||
import * as https from 'https';
|
import * as https from 'https';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as os from 'os';
|
|
||||||
import { URL } from 'url';
|
import { URL } from 'url';
|
||||||
import { ToolNameMapper, type Tool, type ContentBlock } from './tool-name-mapper';
|
import { ToolNameMapper, type Tool, type ContentBlock } from './tool-name-mapper';
|
||||||
|
import { getCcsDir } from '../utils/config-manager';
|
||||||
|
|
||||||
export interface ToolSanitizationProxyConfig {
|
export interface ToolSanitizationProxyConfig {
|
||||||
/** Upstream CLIProxy URL */
|
/** Upstream CLIProxy URL */
|
||||||
@@ -28,6 +28,10 @@ export interface ToolSanitizationProxyConfig {
|
|||||||
timeoutMs?: number;
|
timeoutMs?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type guard to check if a value is a plain object (Record).
|
||||||
|
* Used for safely accessing properties on unknown JSON values.
|
||||||
|
*/
|
||||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||||
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
||||||
}
|
}
|
||||||
@@ -54,8 +58,7 @@ export class ToolSanitizationProxy {
|
|||||||
* Initialize log file path and ensure directory exists.
|
* Initialize log file path and ensure directory exists.
|
||||||
*/
|
*/
|
||||||
private initLogFile(): string {
|
private initLogFile(): string {
|
||||||
const ccsDir = process.env.CCS_HOME || path.join(os.homedir(), '.ccs');
|
const logsDir = path.join(getCcsDir(), 'logs');
|
||||||
const logsDir = path.join(ccsDir, 'logs');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!fs.existsSync(logsDir)) {
|
if (!fs.existsSync(logsDir)) {
|
||||||
@@ -63,6 +66,7 @@ export class ToolSanitizationProxy {
|
|||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// Fallback to temp directory if logs dir creation fails
|
// Fallback to temp directory if logs dir creation fails
|
||||||
|
const os = require('os');
|
||||||
return path.join(os.tmpdir(), 'tool-sanitization-proxy.log');
|
return path.join(os.tmpdir(), 'tool-sanitization-proxy.log');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user