Commit Graph
12 Commits
Author SHA1 Message Date
Tam Nhu Tran f63e2cd5a3 fix(cliproxy): denylist deprecated agy 4.5 models 2026-03-03 03:10:53 +07:00
Tam Nhu Tran 6429781e8f fix(cliproxy): normalize provider-aware Claude model IDs 2026-02-21 02:14:09 +07:00
kaitranntt 917f0bbef7 test(cliproxy): add edge case coverage for Gemini schema sanitizer
Add tests for: exclusiveMinimum/exclusiveMaximum/multipleOf stripping,
uniqueItems/contains/additionalItems stripping, writeOnly/definitions
stripping, example with array values, default with complex nested
objects, empty properties/anyOf edge cases.

Fix proxy log message to say "Gemini-unsupported" instead of
"non-standard".
2026-02-07 06:25:29 -05:00
kaitranntt 1b3440b939 refactor(cliproxy): extract SSE lifecycle tracker and add backpressure handling
Consolidate 5 duplicate boolean tracking variables into a lifecycle
object with an update() method, reducing event detection from 4
locations to centralized calls. Add pause/drain/resume backpressure
to the passthrough path to prevent unbounded memory buffering with
slow clients.
2026-02-07 05:40:24 -05:00
kaitranntt 42a3eb1506 refactor(cliproxy): check lifecycle events in remaining SSE buffer
Add message_start/message_delta/message_stop detection to the
remaining-buffer block in the SSE processing path for defensive
completeness. Addresses code review feedback on PR #493.
2026-02-07 04:30:42 -05:00
kaitranntt 152f5432ae refactor(cliproxy): deduplicate message_delta/message_stop in synthetic SSE response
Track hasReceivedMessageDelta and hasReceivedMessageStop in both
streaming paths (pipe-through and SSE-processing). Conditionally
omit these events from buildSyntheticErrorResponse() when upstream
already sent them, preventing protocol violations.

Closes #491
2026-02-07 04:24:54 -05:00
Kai (Tam Nhu) TranandGitHub 545c8b9515 fix(cliproxy): guard against empty upstream SSE responses in agy profile (#489)
* fix(cliproxy): guard against empty upstream SSE responses in agy profile

When CLIProxyAPIPlus drops unsigned thinking blocks during sub-agent
execution, the response stream can contain no content_block_start or
message_delta events. This causes Claude Code CLI to crash with
"No assistant message found".

Add empty response detection in the tool sanitization proxy's streaming
handler. Both the pipe-through and SSE-processing paths now track
whether meaningful content was received. If upstream sent data but no
content blocks on a 200 OK, a synthetic minimal valid SSE response is
injected to prevent the client crash and surface a clear error message.

Closes #350

* fix(cliproxy): improve empty response detection and add tests

Address code review findings:
- Remove message_delta from content detection (lifecycle event, not
  content); only content_block_start indicates actual content
- Add try-catch in end handlers to handle client disconnects gracefully
- Add 3 integration tests: empty stream injection, normal stream
  passthrough, 4xx/5xx non-injection

* fix(cliproxy): avoid duplicate message_start in synthetic response

Track whether upstream already sent a message_start event. When
injecting the synthetic error response, omit message_start if upstream
already sent one, preventing duplicate events in the SSE stream.

Addresses PR review feedback from ccs-reviewer[bot].

* test(cliproxy): add SSE processing path and real failure mode tests

Address code review observations:
- Add test exercising SSE processing path (sanitized tool names) for
  empty response detection, ensuring both code paths are covered
- Add test mirroring real failure mode where upstream sends only
  message_start then ends abruptly (no message_delta/message_stop)
- Document duplicate message_start assumption with inline comment
2026-02-07 04:09:30 -05:00
Kai (Tam Nhu) TranandGitHub f8c179f6da fix(cliproxy): sanitize MCP tool input_schema to remove non-standard properties (#459)
Squash merge PR #459: MCP tool input_schema sanitization

Fixes #456 - Gemini/Vertex APIs reject non-standard JSON Schema properties from MCP tools

Changes:
- Add allowlist-based schema sanitizer for JSON Schema Draft-07 keywords
- Recursive sanitization with circular ref protection and depth limit
- Handle all schema containers: properties, items, additionalProperties, additionalItems, oneOf/anyOf/allOf, not, if/then/else, $defs, definitions, patternProperties, contains, propertyNames, dependencies
- 22 unit tests covering edge cases
- Integrates into ToolSanitizationProxy pipeline before tool name sanitization
2026-02-04 20:19:58 -05:00
kaitranntt 98b7f6f454 fix(cliproxy): address PR #399 review suggestions
- Move require('os') to top-level import
- Add debug logging for log dir creation failures
- Add hash collision detection and warning in ToolNameMapper
- Clarify proxy chain order comments in cliproxy-executor
2026-01-29 17:49:32 -05:00
kaitranntt d86c53146a 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
2026-01-29 17:28:45 -05:00
kaitranntt 4d292c62e4 fix(cliproxy): route proxy logs to file instead of stderr
- Add file-based logging to ~/.ccs/logs/tool-sanitization-proxy.log
- Console output only when CCS_DEBUG=1 (prevents polluting Claude CLI output)
- Fallback to temp directory if logs dir creation fails
- Respects CCS_HOME for test isolation
2026-01-29 17:21:06 -05:00
kaitranntt 63633507d2 feat(cliproxy): add ToolSanitizationProxy for Gemini 64-char limit
Fixes #219 - MCP tool names exceeding Gemini's 64-character limit
now get sanitized automatically.

- Add tool-name-sanitizer: dedupe segments + smart truncate with hash
- Add tool-name-mapper: bidirectional mapping for response restoration
- Add tool-sanitization-proxy: HTTP proxy layer for all CLIProxy providers
- Chain: Claude CLI → ToolSanitizationProxy → [CodexReasoningProxy] → CLIProxy
- Add unit tests for sanitizer and mapper modules
2026-01-29 16:04:17 -05:00