Skip to content

feat(zai): add GLM-5.2 support#1689

Merged
kevincodex1 merged 4 commits into
Gitlawb:mainfrom
chioarub:feat/zai-glm-5-2-thinking
Jun 19, 2026
Merged

feat(zai): add GLM-5.2 support#1689
kevincodex1 merged 4 commits into
Gitlawb:mainfrom
chioarub:feat/zai-glm-5-2-thinking

Conversation

@chioarub

@chioarub chioarub commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add glm-5.2 model metadata with 1M context and 131,072 max output tokens
  • make glm-5.2 the default Z.AI GLM Coding Plan model
  • add Z.AI-specific thinking request mapping for enabled, disabled, and reasoning-effort overrides
  • preserve GLM reasoning content through tool-call history and add provider-configured tool_stream=true for streaming tool requests
  • update Z.AI setup examples and add focused regression coverage

Validation

  • bun run integrations:check
  • bun run typecheck
  • bun test src/integrations/runtimeMetadata.test.ts src/services/api/providerConfig.test.ts src/services/api/openaiShim.test.ts
  • bun run smoke

Summary by CodeRabbit

  • New Features
    • Set glm-5.2 as the default model (up to 1M context; updated max output tokens).
    • Added Z.AI-compatible query controls for reasoning and thinking (reasoning=high|xhigh, thinking=disabled) with improved request shaping.
    • Enabled tool streaming for glm-5.2 when supported.
  • Documentation
    • Updated .env.example and README for glm-5.2 defaults, /provider OpenAI-compatible setup, and model-query routing guidance (including .env not auto-loaded).
  • Bug Fixes
    • Improved handling of model names with query-string suffixes across matching and runtime limit resolution.
  • Tests
    • Expanded glm-5.2 coverage for reasoning/thinking, tool streaming, and request/response formatting.

@chioarub chioarub changed the title Add Z.AI GLM-5.2 support feat(zai): add GLM-5.2 support Jun 17, 2026
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: cf159bac-89f9-4a18-8519-fa8601158578

📥 Commits

Reviewing files that changed from the base of the PR and between f5b628c and 88bdcbe.

📒 Files selected for processing (2)
  • src/services/api/openaiShim.test.ts
  • src/services/api/openaiShim.ts
📜 Recent review details
🧰 Additional context used
📓 Path-based instructions (13)
src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript with strict mode and ESM imports

Files:

  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
{src/commands/**/*.ts,src/services/**/*.ts,src/entrypoints/**/*.ts}

📄 CodeRabbit inference engine (AGENTS.md)

Use chalk for terminal color in CLI code

Files:

  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
{src/services/**/*.ts,src/utils/**/*.ts}

📄 CodeRabbit inference engine (AGENTS.md)

Use execa for child processes

Files:

  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
{src/integrations/**/*.ts,src/services/**/*.ts}

📄 CodeRabbit inference engine (AGENTS.md)

Test the exact provider/model path you changed when possible for provider modifications

Files:

  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
**/*.{ts,tsx,js,jsx,py,json,md}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Follow the existing code style in the touched files

Files:

  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
**/*.{ts,tsx,js,jsx,py}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Keep comments useful and concise

Files:

  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Follow TypeScript strict mode and type safety practices by running typecheck before submitting

Files:

  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
**/*

⚙️ CodeRabbit configuration file

**/*: Apply the OpenClaude maintainer review rubric from AGENTS.md. Review the current diff, not stale discussion context. Separate real blockers from suggestions. Do not request changes for vague style churn. Treat approval as merge-ready from CodeRabbit's side, pending required human review and GitHub Checks. If checks are failing or unavailable, say so clearly instead of implying the PR is fully ready.

Files:

  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
{src/services/api/**,src/integrations/**,src/utils/model/**,src/utils/provider*.ts,src/commands/provider/**}

⚙️ CodeRabbit configuration file

{src/services/api/**,src/integrations/**,src/utils/model/**,src/utils/provider*.ts,src/commands/provider/**}: Review provider routing, model selection, env precedence, auth/token handling, OpenAI-compatible shims, retries, proxy behavior, and outbound HTTP behavior with high scrutiny. Block on silent default changes, hidden fallback expansion, credential reuse mistakes, hardcoded provider assumptions, or new network reach that is not intentional and documented.

Files:

  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
**

⚙️ CodeRabbit configuration file

**: # AGENTS.md - AI Agent Coding Guide

This guide is for AI coding agents working in the OpenClaude repository. Read it before changing code, and also follow CONTRIBUTING.md for contributor policy, PR expectations, review follow-up, and project scope.

Project Snapshot

OpenClaude is a coding-agent CLI for cloud and local model providers. It supports OpenAI-compatible APIs, Anthropic, Gemini, DeepSeek, Ollama, MCP, local backends, slash commands, tools, agents, and a React/Ink terminal UI.

The installed CLI runs on Node.js >=22.0.0. Bun is used for source builds, scripts, dependency management, and tests.

Work Style

  • Keep changes focused on one problem.
  • Prefer existing patterns in the file or nearby module.
  • Avoid unrelated formatting, renames, dependency changes, or broad rewrites.
  • Add or update tests when behavior changes.
  • Update docs when setup, commands, provider behavior, or user-facing behavior changes.
  • For new features, larger refactors, dependencies, or runtime changes, follow the issue-first guidance in CONTRIBUTING.md.

Stack And Conventions

  • TypeScript with strict mode and ESM imports.
  • React + Ink for terminal UI.
  • Bun lockfile and Bun scripts for development workflows.
  • Node runtime for the built CLI.
  • Python exists for legacy/local-provider helper code. Do not add new Python code or expand Python-based features unless a maintainer explicitly approves that direction.

Common libraries and patterns:

  • chalk for terminal color.
  • commander for CLI argument parsing.
  • execa for child processes.
  • Existing service, provider, settings, permission, and UI patterns over new abstractions.

Repository Map

  • src/commands/ - slash and CLI command implementations.
  • src/components/ - React/Ink UI components.
  • src/services/ - API, MCP, OAuth, wiki, voice, and other service integrations.
  • src/tools/ - tool implementations.
  • src/utils/ - shared utilities.
  • `src/integration...

Files:

  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
**/*.test.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Add or update tests when the change affects behavior

Files:

  • src/services/api/openaiShim.test.ts
**/*.test.{ts,tsx,js}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Test the exact provider/model path you changed when possible

Files:

  • src/services/api/openaiShim.test.ts
{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}

⚙️ CodeRabbit configuration file

{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}: Review tests for meaningful coverage of the changed behavior, isolation of global/env/config state, async cleanup, fake timers, provider profile leaks, and Windows-compatible assumptions. Block when risky runtime changes lack focused regression coverage or tests assert implementation details while missing the user-visible behavior.

Files:

  • src/services/api/openaiShim.test.ts
🔇 Additional comments (2)
src/services/api/openaiShim.ts (1)

216-219: LGTM!

Also applies to: 2526-2544

src/services/api/openaiShim.test.ts (1)

6368-6400: LGTM!

Also applies to: 6439-6472


📝 Walkthrough

Walkthrough

Adds glm-5.2 as the default Z.AI model, replacing GLM-5.1. Introduces a zai-compatible thinking request format in the OpenAI shim for reasoning controls, adds query-string parsing for thinking and reasoning parameters on model names, normalizes model API names to strip query suffixes, and enables tool_stream for Z.AI streaming requests with tools.

Changes

Z.AI GLM-5.2 Integration

Layer / File(s) Summary
Type contracts: ThinkingType, OpenAIShimTransportConfig extensions
src/services/api/providerConfig.ts, src/integrations/descriptors.ts
Adds ThinkingType union ('enabled' | 'disabled'), extends ResolvedProviderRequest and ModelDescriptor with optional thinking field, extends OpenAIShimTransportConfig with 'zai-compatible' in thinkingRequestFormat and a new enableToolStreaming boolean, and adjusts GHE Copilot base URL derivation to use gheUrl ?? rawBaseUrl.
GLM-5.2 model and brand registration
src/integrations/brands/glm.ts, src/integrations/models/glm.ts, src/integrations/vendors/zai.ts
Adds 'glm-5.2' to GLM brand modelIds, registers the glm-5.2 model entry (1M context, 131K output tokens), sets Z.AI defaultModel to glm-5.2, switches thinkingRequestFormat to 'zai-compatible', and adds a catalog entry with enableToolStreaming: true. Removes the prior GLM-5.1 catalog entry.
Model query-string parsing: thinking and reasoning params
src/services/api/providerConfig.ts, src/services/api/providerConfig.test.ts
Introduces parseThinkingType() helper to normalize thinking values, updates parseModelDescriptor() to extract the thinking query param, and propagates descriptor.thinking through resolveProviderRequest(). Tests assert query stripping and parameter extraction for both ?reasoning= and ?thinking= variants.
Model API name normalization (strip query suffix)
src/integrations/runtimeMetadata.ts, src/utils/thinking.ts
Introduces getBaseModelApiName() to trim and remove query-string portions from model strings. Wires it into normalizeModelApiName, findModelDescriptorForApiName, and resolveModelRuntimeLimits for consistent catalog matching. Fixes routeCatalogSupportsThinking to split off ? suffix before lowercasing.
openaiShim: zai-compatible thinking format and tool_stream
src/services/api/openaiShim.ts
Adds normalizeThinkingType() and normalizeZaiReasoningEffort() helpers (xhighmax mapping). Introduces a 'zai-compatible' branch setting body.thinking and body.reasoning_effort from descriptor/request parameters. Refactors the DeepSeek path to reuse normalizeThinkingType(). Sets body.tool_stream = true for streaming chat-completions when enableToolStreaming is active. Removes body.tool_stream on self-heal retries.
Runtime metadata tests for glm-5.2
src/integrations/runtimeMetadata.test.ts
Adds resolveModelRuntimeLimits test for glm-5.2 built-in limits and a parameterized resolveOpenAIShimRuntimeContext suite asserting shim config fields across multiple glm-5.2 query variants.
openaiShim tests for Z.AI GLM-5.2
src/services/api/openaiShim.test.ts
Eleven test groups covering default thinking omission, reasoning= query mapping to reasoning_effort (including xhighmax), thinking=disabled behavior, per-turn override, tool_stream=true for streaming+tools, tool_stream absence for non-matching conditions, thinking round-trip preservation in tool-call messages, verification that non-GLM-5.2 models do not receive GLM-5.2-only reasoning_effort, and tool_stream omission on retry.
Supporting tests and documentation
src/utils/context.test.ts, src/utils/providerFlag.test.ts, src/utils/providerProfiles.test.ts, src/utils/thinking.test.ts, README.md, .env.example, src/services/api/providerConfig.github.test.ts
Updates test expectations for the new default model and glm-5.2 output caps. Adds modelSupportsThinking assertions for ?thinking=disabled query variants. Updates README and .env.example to document glm-5.2 query options and reasoning controls. Adds GHE Copilot base URL expansion test with fallback to OPENAI_BASE_URL.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • Gitlawb/openclaude#1620: Both PRs modify src/integrations/runtimeMetadata.ts's model runtime-limit resolution—this PR normalizes model names by stripping query parameters for catalog matching, while the retrieved PR changes precedence to fall back to cached discovery catalog entries.
  • Gitlawb/openclaude#1685: Both PRs modify GitHub Copilot Enterprise base-URL/routing logic in src/services/api/providerConfig.ts (GHE handling around buildGithubEnterpriseCopilotBaseUrl), so this PR's GHE-related tweak is code-adjacent to the retrieved PR's GHE implementation.

Suggested labels

enhancement

Suggested reviewers

  • jatmn
  • kevincodex1
🚥 Pre-merge checks | ✅ 4 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Risk Surface Disclosed ⚠️ Warning PR touches provider routing (default model/thinkingRequestFormat changes), outbound network behavior (tool_stream parameter), and config behavior, but description doesn't explicitly call out risk s... Add explicit risk surface callout to PR description: note that default model change affects Z.AI provider routing, explain tool_stream implications, and document backwards compatibility strategy.
Description check ❓ Inconclusive The description covers what changed, why, and includes validation results, but deviates from the template structure. Restructure the description to match the provided template: use 'Impact' section with 'user-facing' and 'developer/maintainer' subsections, and replace 'Validation' with 'Testing' checklist format.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change—adding GLM-5.2 support to the Z.AI integration.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
No Hidden Policy Change ✅ Passed All product policy changes (routing default to glm-5.2, thinking format to zai-compatible, tool_stream for glm-5.2) are explicitly documented in PR description. GHE URL fallback logic change is tes...

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chioarub chioarub force-pushed the feat/zai-glm-5-2-thinking branch from 486ab73 to eb29647 Compare June 17, 2026 10:06

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/services/api/openaiShim.test.ts`:
- Around line 6431-6537: Add a new test that validates the retry mutation
behavior for tool_stream stripping during self-heal. Create a test that mocks
the fetch function to return a 400 error with tool_call_incompatible on the
first request and a successful response on the second request for a Z.AI GLM-5.2
streaming request with tools. Capture both the first and second request bodies
and assert that the first request body includes tool_stream set to true while
the second request body omits tool_stream (or has it undefined). This test
should specifically validate that when the createOpenAIShimClient initiates the
beta.messages.create call with the same parameters as the existing positive test
(model glm-5.2, stream true, with tools), the self-heal retry properly strips
out the tool_stream parameter.

In `@src/services/api/openaiShim.ts`:
- Around line 2513-2516: The zaiThinkingType assignment uses
request.thinking?.type as a fallback without normalization, allowing adaptive
values from model/query overlays to bypass enabled/disabled handling. In the
openaiShim.ts file around the zaiThinkingType variable assignment, apply
normalizeThinkingType() to the request.thinking?.type fallback value to ensure
consistent normalization of all thinking type sources, matching the treatment
already applied to requestedThinkingType. This prevents silent provider behavior
drift when reasoning effort is not explicitly set.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c6c89105-48d0-4c14-993a-f8fdb38c3d17

📥 Commits

Reviewing files that changed from the base of the PR and between 2351811 and eb29647.

📒 Files selected for processing (17)
  • .env.example
  • README.md
  • src/integrations/brands/glm.ts
  • src/integrations/descriptors.ts
  • src/integrations/models/glm.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/integrations/runtimeMetadata.ts
  • src/integrations/vendors/zai.ts
  • src/services/api/openaiShim.test.ts
  • src/services/api/openaiShim.ts
  • src/services/api/providerConfig.test.ts
  • src/services/api/providerConfig.ts
  • src/utils/context.test.ts
  • src/utils/providerFlag.test.ts
  • src/utils/providerProfiles.test.ts
  • src/utils/thinking.test.ts
  • src/utils/thinking.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (16)
src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript with strict mode and ESM imports

Files:

  • src/integrations/models/glm.ts
  • src/utils/thinking.ts
  • src/utils/providerFlag.test.ts
  • src/utils/thinking.test.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/integrations/descriptors.ts
  • src/integrations/brands/glm.ts
  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.test.ts
  • src/integrations/runtimeMetadata.ts
  • src/integrations/vendors/zai.ts
  • src/services/api/openaiShim.ts
  • src/services/api/providerConfig.ts
  • src/utils/context.test.ts
  • src/services/api/openaiShim.test.ts
{src/integrations/**/*.ts,src/services/**/*.ts}

📄 CodeRabbit inference engine (AGENTS.md)

Test the exact provider/model path you changed when possible for provider modifications

Files:

  • src/integrations/models/glm.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/integrations/descriptors.ts
  • src/integrations/brands/glm.ts
  • src/services/api/providerConfig.test.ts
  • src/integrations/runtimeMetadata.ts
  • src/integrations/vendors/zai.ts
  • src/services/api/openaiShim.ts
  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.test.ts
src/integrations/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

Check existing provider implementations before adding a new pattern

Files:

  • src/integrations/models/glm.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/integrations/descriptors.ts
  • src/integrations/brands/glm.ts
  • src/integrations/runtimeMetadata.ts
  • src/integrations/vendors/zai.ts
**/*.{ts,tsx,js,jsx,py,json,md}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Follow the existing code style in the touched files

Files:

  • src/integrations/models/glm.ts
  • src/utils/thinking.ts
  • src/utils/providerFlag.test.ts
  • src/utils/thinking.test.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/integrations/descriptors.ts
  • src/integrations/brands/glm.ts
  • src/utils/providerProfiles.test.ts
  • README.md
  • src/services/api/providerConfig.test.ts
  • src/integrations/runtimeMetadata.ts
  • src/integrations/vendors/zai.ts
  • src/services/api/openaiShim.ts
  • src/services/api/providerConfig.ts
  • src/utils/context.test.ts
  • src/services/api/openaiShim.test.ts
**/*.{ts,tsx,js,jsx,py}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Keep comments useful and concise

Files:

  • src/integrations/models/glm.ts
  • src/utils/thinking.ts
  • src/utils/providerFlag.test.ts
  • src/utils/thinking.test.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/integrations/descriptors.ts
  • src/integrations/brands/glm.ts
  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.test.ts
  • src/integrations/runtimeMetadata.ts
  • src/integrations/vendors/zai.ts
  • src/services/api/openaiShim.ts
  • src/services/api/providerConfig.ts
  • src/utils/context.test.ts
  • src/services/api/openaiShim.test.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Follow TypeScript strict mode and type safety practices by running typecheck before submitting

Files:

  • src/integrations/models/glm.ts
  • src/utils/thinking.ts
  • src/utils/providerFlag.test.ts
  • src/utils/thinking.test.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/integrations/descriptors.ts
  • src/integrations/brands/glm.ts
  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.test.ts
  • src/integrations/runtimeMetadata.ts
  • src/integrations/vendors/zai.ts
  • src/services/api/openaiShim.ts
  • src/services/api/providerConfig.ts
  • src/utils/context.test.ts
  • src/services/api/openaiShim.test.ts
**/*

⚙️ CodeRabbit configuration file

**/*: Apply the OpenClaude maintainer review rubric from AGENTS.md. Review the current diff, not stale discussion context. Separate real blockers from suggestions. Do not request changes for vague style churn. Treat approval as merge-ready from CodeRabbit's side, pending required human review and GitHub Checks. If checks are failing or unavailable, say so clearly instead of implying the PR is fully ready.

Files:

  • src/integrations/models/glm.ts
  • src/utils/thinking.ts
  • src/utils/providerFlag.test.ts
  • src/utils/thinking.test.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/integrations/descriptors.ts
  • src/integrations/brands/glm.ts
  • src/utils/providerProfiles.test.ts
  • README.md
  • src/services/api/providerConfig.test.ts
  • src/integrations/runtimeMetadata.ts
  • src/integrations/vendors/zai.ts
  • src/services/api/openaiShim.ts
  • src/services/api/providerConfig.ts
  • src/utils/context.test.ts
  • src/services/api/openaiShim.test.ts
{src/services/api/**,src/integrations/**,src/utils/model/**,src/utils/provider*.ts,src/commands/provider/**}

⚙️ CodeRabbit configuration file

{src/services/api/**,src/integrations/**,src/utils/model/**,src/utils/provider*.ts,src/commands/provider/**}: Review provider routing, model selection, env precedence, auth/token handling, OpenAI-compatible shims, retries, proxy behavior, and outbound HTTP behavior with high scrutiny. Block on silent default changes, hidden fallback expansion, credential reuse mistakes, hardcoded provider assumptions, or new network reach that is not intentional and documented.

Files:

  • src/integrations/models/glm.ts
  • src/utils/providerFlag.test.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/integrations/descriptors.ts
  • src/integrations/brands/glm.ts
  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.test.ts
  • src/integrations/runtimeMetadata.ts
  • src/integrations/vendors/zai.ts
  • src/services/api/openaiShim.ts
  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.test.ts
**

⚙️ CodeRabbit configuration file

**: # AGENTS.md - AI Agent Coding Guide

This guide is for AI coding agents working in the OpenClaude repository. Read it before changing code, and also follow CONTRIBUTING.md for contributor policy, PR expectations, review follow-up, and project scope.

Project Snapshot

OpenClaude is a coding-agent CLI for cloud and local model providers. It supports OpenAI-compatible APIs, Anthropic, Gemini, DeepSeek, Ollama, MCP, local backends, slash commands, tools, agents, and a React/Ink terminal UI.

The installed CLI runs on Node.js >=22.0.0. Bun is used for source builds, scripts, dependency management, and tests.

Work Style

  • Keep changes focused on one problem.
  • Prefer existing patterns in the file or nearby module.
  • Avoid unrelated formatting, renames, dependency changes, or broad rewrites.
  • Add or update tests when behavior changes.
  • Update docs when setup, commands, provider behavior, or user-facing behavior changes.
  • For new features, larger refactors, dependencies, or runtime changes, follow the issue-first guidance in CONTRIBUTING.md.

Stack And Conventions

  • TypeScript with strict mode and ESM imports.
  • React + Ink for terminal UI.
  • Bun lockfile and Bun scripts for development workflows.
  • Node runtime for the built CLI.
  • Python exists for legacy/local-provider helper code. Do not add new Python code or expand Python-based features unless a maintainer explicitly approves that direction.

Common libraries and patterns:

  • chalk for terminal color.
  • commander for CLI argument parsing.
  • execa for child processes.
  • Existing service, provider, settings, permission, and UI patterns over new abstractions.

Repository Map

  • src/commands/ - slash and CLI command implementations.
  • src/components/ - React/Ink UI components.
  • src/services/ - API, MCP, OAuth, wiki, voice, and other service integrations.
  • src/tools/ - tool implementations.
  • src/utils/ - shared utilities.
  • `src/integration...

Files:

  • src/integrations/models/glm.ts
  • src/utils/thinking.ts
  • src/utils/providerFlag.test.ts
  • src/utils/thinking.test.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/integrations/descriptors.ts
  • src/integrations/brands/glm.ts
  • src/utils/providerProfiles.test.ts
  • README.md
  • src/services/api/providerConfig.test.ts
  • src/integrations/runtimeMetadata.ts
  • src/integrations/vendors/zai.ts
  • src/services/api/openaiShim.ts
  • src/services/api/providerConfig.ts
  • src/utils/context.test.ts
  • src/services/api/openaiShim.test.ts
{src/services/**/*.ts,src/utils/**/*.ts}

📄 CodeRabbit inference engine (AGENTS.md)

Use execa for child processes

Files:

  • src/utils/thinking.ts
  • src/utils/providerFlag.test.ts
  • src/utils/thinking.test.ts
  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.test.ts
  • src/services/api/openaiShim.ts
  • src/services/api/providerConfig.ts
  • src/utils/context.test.ts
  • src/services/api/openaiShim.test.ts
**/*.test.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Add or update tests when the change affects behavior

Files:

  • src/utils/providerFlag.test.ts
  • src/utils/thinking.test.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.test.ts
  • src/utils/context.test.ts
  • src/services/api/openaiShim.test.ts
src/**/*provider*.{ts,tsx,js}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Provider implementations must follow documented patterns in docs/integrations/

Files:

  • src/utils/providerFlag.test.ts
  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.test.ts
  • src/services/api/providerConfig.ts
**/*.test.{ts,tsx,js}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Test the exact provider/model path you changed when possible

Files:

  • src/utils/providerFlag.test.ts
  • src/utils/thinking.test.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.test.ts
  • src/utils/context.test.ts
  • src/services/api/openaiShim.test.ts
{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}

⚙️ CodeRabbit configuration file

{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}: Review tests for meaningful coverage of the changed behavior, isolation of global/env/config state, async cleanup, fake timers, provider profile leaks, and Windows-compatible assumptions. Block when risky runtime changes lack focused regression coverage or tests assert implementation details while missing the user-visible behavior.

Files:

  • src/utils/providerFlag.test.ts
  • src/utils/thinking.test.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.test.ts
  • src/utils/context.test.ts
  • src/services/api/openaiShim.test.ts
{README.md,CONTRIBUTING.md,docs/**,.github/pull_request_template.md}

⚙️ CodeRabbit configuration file

{README.md,CONTRIBUTING.md,docs/**,.github/pull_request_template.md}: Review docs for accuracy against current code behavior. Flag security or provider claims that overpromise, stale install commands, missing setup caveats, and instructions that could push users toward unsafe credential handling. Keep purely wording-level suggestions non-blocking.

Files:

  • README.md
{src/commands/**/*.ts,src/services/**/*.ts,src/entrypoints/**/*.ts}

📄 CodeRabbit inference engine (AGENTS.md)

Use chalk for terminal color in CLI code

Files:

  • src/services/api/providerConfig.test.ts
  • src/services/api/openaiShim.ts
  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.test.ts
🔇 Additional comments (16)
src/services/api/providerConfig.test.ts (1)

5-26: LGTM!

src/integrations/runtimeMetadata.ts (1)

32-45: LGTM!

Also applies to: 284-289, 400-417

src/utils/thinking.ts (1)

93-97: LGTM!

src/integrations/runtimeMetadata.test.ts (1)

74-105: LGTM!

src/services/api/openaiShim.ts (1)

210-227: LGTM!

Also applies to: 2495-2510, 2543-2549, 3280-3283

src/services/api/providerConfig.ts (1)

113-130: LGTM!

Also applies to: 146-148, 253-259, 319-326, 787-787

src/integrations/descriptors.ts (1)

40-41: LGTM!

src/integrations/brands/glm.ts (1)

16-16: LGTM!

src/integrations/models/glm.ts (1)

32-32: LGTM!

src/integrations/vendors/zai.ts (1)

8-8: LGTM!

Also applies to: 21-21, 47-57

README.md (1)

195-195: LGTM!

Also applies to: 229-229, 263-263, 284-284

src/utils/context.test.ts (1)

721-743: Test updates for Z.AI GLM context windows and output caps are accurate.

The glm-5.2 assertions correctly reflect the 1M context window and 131K output token limits stated in the PR objectives. Preserving existing GLM uppercase-variant assertions ensures backward compatibility.

src/utils/providerFlag.test.ts (1)

515-515: Default model expectation correctly updated to reflect vendor change.

The expected OPENAI_MODEL now matches the Z.AI vendor's defaultModel configuration of glm-5.2.

src/utils/providerProfiles.test.ts (1)

1525-1525: Preset defaults test aligned with upstream vendor configuration.

The expected model now matches the Z.AI defaultModel of glm-5.2.

src/utils/thinking.test.ts (1)

82-83: Query-string thinking parameter variants correctly tested.

Both space-present and space-absent query parameter variants (?thinking=disabled and ?thinking=disabled) are tested, validating the query-string parsing and stripping behavior described in the PR stack.

.env.example (1)

174-181: Z.AI GLM-5.2 documentation examples are clear and complete.

The expanded examples demonstrate the primary glm-5.2 model, optional thinking control query parameters (reasoning=high, reasoning=xhigh, thinking=disabled), and alternative GLM model names. Users now have explicit guidance for GLM-5.2 reasoning-effort control.

Comment thread src/services/api/openaiShim.test.ts
Comment thread src/services/api/openaiShim.ts
@chioarub chioarub force-pushed the feat/zai-glm-5-2-thinking branch from eb29647 to 6940c5e Compare June 17, 2026 10:20

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/services/api/openaiShim.ts`:
- Around line 2512-2531: The code contains a redundant assignment of
body.thinking to { type: 'enabled' } that occurs both in the else if block for
zaiThinkingType === 'enabled' (line 2522) and again in the subsequent if block
when zaiThinkingType !== 'disabled' and request.reasoning?.effort exists (line
2526). Remove the redundant body.thinking assignment from inside the if block
that handles request.reasoning?.effort, keeping only the
normalizeZaiReasoningEffort assignment, since the thinking type is already set
to 'enabled' in the preceding else-if block.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 24f74b76-a77c-479a-b15b-176c1590756a

📥 Commits

Reviewing files that changed from the base of the PR and between eb29647 and 6940c5e.

📒 Files selected for processing (17)
  • .env.example
  • README.md
  • src/integrations/brands/glm.ts
  • src/integrations/descriptors.ts
  • src/integrations/models/glm.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/integrations/runtimeMetadata.ts
  • src/integrations/vendors/zai.ts
  • src/services/api/openaiShim.test.ts
  • src/services/api/openaiShim.ts
  • src/services/api/providerConfig.test.ts
  • src/services/api/providerConfig.ts
  • src/utils/context.test.ts
  • src/utils/providerFlag.test.ts
  • src/utils/providerProfiles.test.ts
  • src/utils/thinking.test.ts
  • src/utils/thinking.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (16)
src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript with strict mode and ESM imports

Files:

  • src/integrations/brands/glm.ts
  • src/utils/thinking.test.ts
  • src/integrations/models/glm.ts
  • src/utils/thinking.ts
  • src/integrations/descriptors.ts
  • src/utils/providerFlag.test.ts
  • src/services/api/providerConfig.test.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/utils/context.test.ts
  • src/integrations/vendors/zai.ts
  • src/integrations/runtimeMetadata.ts
  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
{src/integrations/**/*.ts,src/services/**/*.ts}

📄 CodeRabbit inference engine (AGENTS.md)

Test the exact provider/model path you changed when possible for provider modifications

Files:

  • src/integrations/brands/glm.ts
  • src/integrations/models/glm.ts
  • src/integrations/descriptors.ts
  • src/services/api/providerConfig.test.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/integrations/vendors/zai.ts
  • src/integrations/runtimeMetadata.ts
  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
src/integrations/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

Check existing provider implementations before adding a new pattern

Files:

  • src/integrations/brands/glm.ts
  • src/integrations/models/glm.ts
  • src/integrations/descriptors.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/integrations/vendors/zai.ts
  • src/integrations/runtimeMetadata.ts
**/*.{ts,tsx,js,jsx,py,json,md}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Follow the existing code style in the touched files

Files:

  • src/integrations/brands/glm.ts
  • src/utils/thinking.test.ts
  • src/integrations/models/glm.ts
  • src/utils/thinking.ts
  • src/integrations/descriptors.ts
  • src/utils/providerFlag.test.ts
  • src/services/api/providerConfig.test.ts
  • src/integrations/runtimeMetadata.test.ts
  • README.md
  • src/utils/context.test.ts
  • src/integrations/vendors/zai.ts
  • src/integrations/runtimeMetadata.ts
  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
**/*.{ts,tsx,js,jsx,py}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Keep comments useful and concise

Files:

  • src/integrations/brands/glm.ts
  • src/utils/thinking.test.ts
  • src/integrations/models/glm.ts
  • src/utils/thinking.ts
  • src/integrations/descriptors.ts
  • src/utils/providerFlag.test.ts
  • src/services/api/providerConfig.test.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/utils/context.test.ts
  • src/integrations/vendors/zai.ts
  • src/integrations/runtimeMetadata.ts
  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Follow TypeScript strict mode and type safety practices by running typecheck before submitting

Files:

  • src/integrations/brands/glm.ts
  • src/utils/thinking.test.ts
  • src/integrations/models/glm.ts
  • src/utils/thinking.ts
  • src/integrations/descriptors.ts
  • src/utils/providerFlag.test.ts
  • src/services/api/providerConfig.test.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/utils/context.test.ts
  • src/integrations/vendors/zai.ts
  • src/integrations/runtimeMetadata.ts
  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
**/*

⚙️ CodeRabbit configuration file

**/*: Apply the OpenClaude maintainer review rubric from AGENTS.md. Review the current diff, not stale discussion context. Separate real blockers from suggestions. Do not request changes for vague style churn. Treat approval as merge-ready from CodeRabbit's side, pending required human review and GitHub Checks. If checks are failing or unavailable, say so clearly instead of implying the PR is fully ready.

Files:

  • src/integrations/brands/glm.ts
  • src/utils/thinking.test.ts
  • src/integrations/models/glm.ts
  • src/utils/thinking.ts
  • src/integrations/descriptors.ts
  • src/utils/providerFlag.test.ts
  • src/services/api/providerConfig.test.ts
  • src/integrations/runtimeMetadata.test.ts
  • README.md
  • src/utils/context.test.ts
  • src/integrations/vendors/zai.ts
  • src/integrations/runtimeMetadata.ts
  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
{src/services/api/**,src/integrations/**,src/utils/model/**,src/utils/provider*.ts,src/commands/provider/**}

⚙️ CodeRabbit configuration file

{src/services/api/**,src/integrations/**,src/utils/model/**,src/utils/provider*.ts,src/commands/provider/**}: Review provider routing, model selection, env precedence, auth/token handling, OpenAI-compatible shims, retries, proxy behavior, and outbound HTTP behavior with high scrutiny. Block on silent default changes, hidden fallback expansion, credential reuse mistakes, hardcoded provider assumptions, or new network reach that is not intentional and documented.

Files:

  • src/integrations/brands/glm.ts
  • src/integrations/models/glm.ts
  • src/integrations/descriptors.ts
  • src/utils/providerFlag.test.ts
  • src/services/api/providerConfig.test.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/integrations/vendors/zai.ts
  • src/integrations/runtimeMetadata.ts
  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
**

⚙️ CodeRabbit configuration file

**: # AGENTS.md - AI Agent Coding Guide

This guide is for AI coding agents working in the OpenClaude repository. Read it before changing code, and also follow CONTRIBUTING.md for contributor policy, PR expectations, review follow-up, and project scope.

Project Snapshot

OpenClaude is a coding-agent CLI for cloud and local model providers. It supports OpenAI-compatible APIs, Anthropic, Gemini, DeepSeek, Ollama, MCP, local backends, slash commands, tools, agents, and a React/Ink terminal UI.

The installed CLI runs on Node.js >=22.0.0. Bun is used for source builds, scripts, dependency management, and tests.

Work Style

  • Keep changes focused on one problem.
  • Prefer existing patterns in the file or nearby module.
  • Avoid unrelated formatting, renames, dependency changes, or broad rewrites.
  • Add or update tests when behavior changes.
  • Update docs when setup, commands, provider behavior, or user-facing behavior changes.
  • For new features, larger refactors, dependencies, or runtime changes, follow the issue-first guidance in CONTRIBUTING.md.

Stack And Conventions

  • TypeScript with strict mode and ESM imports.
  • React + Ink for terminal UI.
  • Bun lockfile and Bun scripts for development workflows.
  • Node runtime for the built CLI.
  • Python exists for legacy/local-provider helper code. Do not add new Python code or expand Python-based features unless a maintainer explicitly approves that direction.

Common libraries and patterns:

  • chalk for terminal color.
  • commander for CLI argument parsing.
  • execa for child processes.
  • Existing service, provider, settings, permission, and UI patterns over new abstractions.

Repository Map

  • src/commands/ - slash and CLI command implementations.
  • src/components/ - React/Ink UI components.
  • src/services/ - API, MCP, OAuth, wiki, voice, and other service integrations.
  • src/tools/ - tool implementations.
  • src/utils/ - shared utilities.
  • `src/integration...

Files:

  • src/integrations/brands/glm.ts
  • src/utils/thinking.test.ts
  • src/integrations/models/glm.ts
  • src/utils/thinking.ts
  • src/integrations/descriptors.ts
  • src/utils/providerFlag.test.ts
  • src/services/api/providerConfig.test.ts
  • src/integrations/runtimeMetadata.test.ts
  • README.md
  • src/utils/context.test.ts
  • src/integrations/vendors/zai.ts
  • src/integrations/runtimeMetadata.ts
  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
{src/services/**/*.ts,src/utils/**/*.ts}

📄 CodeRabbit inference engine (AGENTS.md)

Use execa for child processes

Files:

  • src/utils/thinking.test.ts
  • src/utils/thinking.ts
  • src/utils/providerFlag.test.ts
  • src/services/api/providerConfig.test.ts
  • src/utils/context.test.ts
  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
**/*.test.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Add or update tests when the change affects behavior

Files:

  • src/utils/thinking.test.ts
  • src/utils/providerFlag.test.ts
  • src/services/api/providerConfig.test.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/utils/context.test.ts
  • src/utils/providerProfiles.test.ts
  • src/services/api/openaiShim.test.ts
**/*.test.{ts,tsx,js}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Test the exact provider/model path you changed when possible

Files:

  • src/utils/thinking.test.ts
  • src/utils/providerFlag.test.ts
  • src/services/api/providerConfig.test.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/utils/context.test.ts
  • src/utils/providerProfiles.test.ts
  • src/services/api/openaiShim.test.ts
{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}

⚙️ CodeRabbit configuration file

{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}: Review tests for meaningful coverage of the changed behavior, isolation of global/env/config state, async cleanup, fake timers, provider profile leaks, and Windows-compatible assumptions. Block when risky runtime changes lack focused regression coverage or tests assert implementation details while missing the user-visible behavior.

Files:

  • src/utils/thinking.test.ts
  • src/utils/providerFlag.test.ts
  • src/services/api/providerConfig.test.ts
  • src/integrations/runtimeMetadata.test.ts
  • src/utils/context.test.ts
  • src/utils/providerProfiles.test.ts
  • src/services/api/openaiShim.test.ts
src/**/*provider*.{ts,tsx,js}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Provider implementations must follow documented patterns in docs/integrations/

Files:

  • src/utils/providerFlag.test.ts
  • src/services/api/providerConfig.test.ts
  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.ts
{src/commands/**/*.ts,src/services/**/*.ts,src/entrypoints/**/*.ts}

📄 CodeRabbit inference engine (AGENTS.md)

Use chalk for terminal color in CLI code

Files:

  • src/services/api/providerConfig.test.ts
  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
{README.md,CONTRIBUTING.md,docs/**,.github/pull_request_template.md}

⚙️ CodeRabbit configuration file

{README.md,CONTRIBUTING.md,docs/**,.github/pull_request_template.md}: Review docs for accuracy against current code behavior. Flag security or provider claims that overpromise, stale install commands, missing setup caveats, and instructions that could push users toward unsafe credential handling. Keep purely wording-level suggestions non-blocking.

Files:

  • README.md
🔇 Additional comments (29)
src/services/api/providerConfig.test.ts (1)

1-27: LGTM!

src/integrations/runtimeMetadata.ts (1)

32-46: LGTM!

Also applies to: 284-289, 400-417

src/utils/thinking.ts (1)

93-93: LGTM!

src/services/api/openaiShim.ts (4)

210-227: LGTM!


2495-2510: LGTM!


2544-2550: LGTM!


2283-2283: LGTM!

src/integrations/runtimeMetadata.test.ts (1)

74-85: LGTM!

Also applies to: 87-105

src/services/api/openaiShim.test.ts (1)

5154-5154: LGTM!

Also applies to: 6299-6643

src/services/api/providerConfig.ts (5)

113-113: LGTM!

Also applies to: 128-130


146-148: LGTM!


253-259: LGTM!


319-319: LGTM!

Also applies to: 325-325


787-787: LGTM!

src/integrations/descriptors.ts (1)

40-41: LGTM!

src/integrations/brands/glm.ts (1)

16-16: LGTM!

src/integrations/models/glm.ts (1)

32-32: LGTM!

src/integrations/vendors/zai.ts (3)

8-8: LGTM!


21-21: LGTM!


47-57: LGTM!

README.md (4)

195-195: LGTM!


229-229: LGTM!


263-263: LGTM!


284-284: LGTM!

src/utils/context.test.ts (1)

721-729: LGTM!

src/utils/providerFlag.test.ts (1)

515-515: LGTM!

src/utils/providerProfiles.test.ts (1)

1525-1525: LGTM!

src/utils/thinking.test.ts (1)

82-83: LGTM!

.env.example (1)

176-181: LGTM!

Comment thread src/services/api/openaiShim.ts
@chioarub chioarub force-pushed the feat/zai-glm-5-2-thinking branch from 6940c5e to e97dec4 Compare June 17, 2026 10:33
kevincodex1
kevincodex1 previously approved these changes Jun 17, 2026

@kevincodex1 kevincodex1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM . please check too @jatmn

jatmn
jatmn previously approved these changes Jun 17, 2026

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Line 108: The note on line 108 overstates the security guarantee by claiming
the `/provider` command "securely stores credentials" when the actual storage
mechanism is the `.openclaude-profile.json` file, which may not be encrypted or
keychain-backed. Replace the phrase "securely stores credentials" with a more
accurate description that specifies the credentials are persisted to
`.openclaude-profile.json` and avoid implying encryption or advanced security
measures unless that protection is actually implemented.

In `@src/services/api/providerConfig.ts`:
- Around line 822-841: The gheCopilotBaseUrl variable is only derived from
githubEnterpriseEnvUrl (gheUrl), but when isGithubGhe is true due to rawBaseUrl
being set and githubEnterpriseEnvUrl is unset, gheCopilotBaseUrl remains
undefined. This causes the base URL rewrite at lines 893-900 to fail. Fix this
by also checking if rawBaseUrl is a GHE host when gheUrl is undefined, and use
buildGithubEnterpriseCopilotBaseUrl with rawBaseUrl in that case to ensure
gheCopilotBaseUrl is properly set. Additionally, add a regression test in
src/services/api/providerConfig.test.ts covering the scenario where GitHub mode
is enabled with a GHE OPENAI_BASE_URL but no GITHUB_ENTERPRISE_URL, asserting
that the final baseUrl includes the .../api/copilot path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 72522fba-4818-469c-9263-f3548decbb7c

📥 Commits

Reviewing files that changed from the base of the PR and between e97dec4 and 9b6a55e.

📒 Files selected for processing (6)
  • .env.example
  • README.md
  • src/services/api/openaiShim.test.ts
  • src/services/api/openaiShim.ts
  • src/services/api/providerConfig.ts
  • src/utils/providerProfiles.test.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (15)
src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript with strict mode and ESM imports

Files:

  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
{src/services/**/*.ts,src/utils/**/*.ts}

📄 CodeRabbit inference engine (AGENTS.md)

Use execa for child processes

Files:

  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
**/*.{ts,tsx,js,jsx,py,json,md}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Follow the existing code style in the touched files

Files:

  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.ts
  • README.md
  • src/services/api/openaiShim.test.ts
**/*.test.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Add or update tests when the change affects behavior

Files:

  • src/utils/providerProfiles.test.ts
  • src/services/api/openaiShim.test.ts
src/**/*provider*.{ts,tsx,js}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Provider implementations must follow documented patterns in docs/integrations/

Files:

  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.ts
**/*.test.{ts,tsx,js}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Test the exact provider/model path you changed when possible

Files:

  • src/utils/providerProfiles.test.ts
  • src/services/api/openaiShim.test.ts
**/*.{ts,tsx,js,jsx,py}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Keep comments useful and concise

Files:

  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Follow TypeScript strict mode and type safety practices by running typecheck before submitting

Files:

  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
**/*

⚙️ CodeRabbit configuration file

**/*: Apply the OpenClaude maintainer review rubric from AGENTS.md. Review the current diff, not stale discussion context. Separate real blockers from suggestions. Do not request changes for vague style churn. Treat approval as merge-ready from CodeRabbit's side, pending required human review and GitHub Checks. If checks are failing or unavailable, say so clearly instead of implying the PR is fully ready.

Files:

  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.ts
  • README.md
  • src/services/api/openaiShim.test.ts
{src/services/api/**,src/integrations/**,src/utils/model/**,src/utils/provider*.ts,src/commands/provider/**}

⚙️ CodeRabbit configuration file

{src/services/api/**,src/integrations/**,src/utils/model/**,src/utils/provider*.ts,src/commands/provider/**}: Review provider routing, model selection, env precedence, auth/token handling, OpenAI-compatible shims, retries, proxy behavior, and outbound HTTP behavior with high scrutiny. Block on silent default changes, hidden fallback expansion, credential reuse mistakes, hardcoded provider assumptions, or new network reach that is not intentional and documented.

Files:

  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}

⚙️ CodeRabbit configuration file

{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}: Review tests for meaningful coverage of the changed behavior, isolation of global/env/config state, async cleanup, fake timers, provider profile leaks, and Windows-compatible assumptions. Block when risky runtime changes lack focused regression coverage or tests assert implementation details while missing the user-visible behavior.

Files:

  • src/utils/providerProfiles.test.ts
  • src/services/api/openaiShim.test.ts
**

⚙️ CodeRabbit configuration file

**: # AGENTS.md - AI Agent Coding Guide

This guide is for AI coding agents working in the OpenClaude repository. Read it before changing code, and also follow CONTRIBUTING.md for contributor policy, PR expectations, review follow-up, and project scope.

Project Snapshot

OpenClaude is a coding-agent CLI for cloud and local model providers. It supports OpenAI-compatible APIs, Anthropic, Gemini, DeepSeek, Ollama, MCP, local backends, slash commands, tools, agents, and a React/Ink terminal UI.

The installed CLI runs on Node.js >=22.0.0. Bun is used for source builds, scripts, dependency management, and tests.

Work Style

  • Keep changes focused on one problem.
  • Prefer existing patterns in the file or nearby module.
  • Avoid unrelated formatting, renames, dependency changes, or broad rewrites.
  • Add or update tests when behavior changes.
  • Update docs when setup, commands, provider behavior, or user-facing behavior changes.
  • For new features, larger refactors, dependencies, or runtime changes, follow the issue-first guidance in CONTRIBUTING.md.

Stack And Conventions

  • TypeScript with strict mode and ESM imports.
  • React + Ink for terminal UI.
  • Bun lockfile and Bun scripts for development workflows.
  • Node runtime for the built CLI.
  • Python exists for legacy/local-provider helper code. Do not add new Python code or expand Python-based features unless a maintainer explicitly approves that direction.

Common libraries and patterns:

  • chalk for terminal color.
  • commander for CLI argument parsing.
  • execa for child processes.
  • Existing service, provider, settings, permission, and UI patterns over new abstractions.

Repository Map

  • src/commands/ - slash and CLI command implementations.
  • src/components/ - React/Ink UI components.
  • src/services/ - API, MCP, OAuth, wiki, voice, and other service integrations.
  • src/tools/ - tool implementations.
  • src/utils/ - shared utilities.
  • `src/integration...

Files:

  • src/utils/providerProfiles.test.ts
  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.ts
  • README.md
  • src/services/api/openaiShim.test.ts
{src/commands/**/*.ts,src/services/**/*.ts,src/entrypoints/**/*.ts}

📄 CodeRabbit inference engine (AGENTS.md)

Use chalk for terminal color in CLI code

Files:

  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
{src/integrations/**/*.ts,src/services/**/*.ts}

📄 CodeRabbit inference engine (AGENTS.md)

Test the exact provider/model path you changed when possible for provider modifications

Files:

  • src/services/api/providerConfig.ts
  • src/services/api/openaiShim.ts
  • src/services/api/openaiShim.test.ts
{README.md,CONTRIBUTING.md,docs/**,.github/pull_request_template.md}

⚙️ CodeRabbit configuration file

{README.md,CONTRIBUTING.md,docs/**,.github/pull_request_template.md}: Review docs for accuracy against current code behavior. Flag security or provider claims that overpromise, stale install commands, missing setup caveats, and instructions that could push users toward unsafe credential handling. Keep purely wording-level suggestions non-blocking.

Files:

  • README.md
🔇 Additional comments (10)
src/services/api/openaiShim.test.ts (1)

21-22: LGTM!

Also applies to: 159-160, 199-200, 972-973, 1016-1044

src/services/api/openaiShim.ts (6)

2471-2471: LGTM!


2547-2553: LGTM!


2516-2534: LGTM!


2284-2290: LGTM!


2529-2533: normalizeZaiReasoningEffort is correctly implemented—maps low, medium, and high to 'high', and xhigh to 'max'. No issues found.


518-523: GitHub credential precedence change is intentional support for GitHub Enterprise authentication.

The credential chain (GITHUB_COPILOT_KEY → OPENAI_API_KEY → GITHUB_TOKEN → GH_TOKEN) aligns with documented behavior in src/integrations/gateways/github-enterprise.ts and is extensively tested in openaiShim.test.ts. The change ensures direct Copilot API keys take priority when available, which is the expected pattern for GitHub Enterprise. No split needed—this is part of the broader GitHub integration work.

src/utils/providerProfiles.test.ts (1)

346-479: LGTM!

Also applies to: 1190-1218, 1261-1270

.env.example (1)

4-15: LGTM!

Also applies to: 143-156, 513-524

README.md (1)

127-129: LGTM!

Also applies to: 193-205, 223-289

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@README.md`:
- Line 108: The note on line 108 overstates the security guarantee by claiming
the `/provider` command "securely stores credentials" when the actual storage
mechanism is the `.openclaude-profile.json` file, which may not be encrypted or
keychain-backed. Replace the phrase "securely stores credentials" with a more
accurate description that specifies the credentials are persisted to
`.openclaude-profile.json` and avoid implying encryption or advanced security
measures unless that protection is actually implemented.

In `@src/services/api/providerConfig.ts`:
- Around line 822-841: The gheCopilotBaseUrl variable is only derived from
githubEnterpriseEnvUrl (gheUrl), but when isGithubGhe is true due to rawBaseUrl
being set and githubEnterpriseEnvUrl is unset, gheCopilotBaseUrl remains
undefined. This causes the base URL rewrite at lines 893-900 to fail. Fix this
by also checking if rawBaseUrl is a GHE host when gheUrl is undefined, and use
buildGithubEnterpriseCopilotBaseUrl with rawBaseUrl in that case to ensure
gheCopilotBaseUrl is properly set. Additionally, add a regression test in
src/services/api/providerConfig.test.ts covering the scenario where GitHub mode
is enabled with a GHE OPENAI_BASE_URL but no GITHUB_ENTERPRISE_URL, asserting
that the final baseUrl includes the .../api/copilot path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 72522fba-4818-469c-9263-f3548decbb7c

📥 Commits

Reviewing files that changed from the base of the PR and between e97dec4 and 9b6a55e.

📒 Files selected for processing (6)
  • .env.example
  • README.md
  • src/services/api/openaiShim.test.ts
  • src/services/api/openaiShim.ts
  • src/services/api/providerConfig.ts
  • src/utils/providerProfiles.test.ts
📜 Review details
🔇 Additional comments (10)
src/services/api/openaiShim.test.ts (1)

21-22: LGTM!

Also applies to: 159-160, 199-200, 972-973, 1016-1044

src/services/api/openaiShim.ts (6)

2471-2471: LGTM!


2547-2553: LGTM!


2516-2534: LGTM!


2284-2290: LGTM!


2529-2533: normalizeZaiReasoningEffort is correctly implemented—maps low, medium, and high to 'high', and xhigh to 'max'. No issues found.


518-523: GitHub credential precedence change is intentional support for GitHub Enterprise authentication.

The credential chain (GITHUB_COPILOT_KEY → OPENAI_API_KEY → GITHUB_TOKEN → GH_TOKEN) aligns with documented behavior in src/integrations/gateways/github-enterprise.ts and is extensively tested in openaiShim.test.ts. The change ensures direct Copilot API keys take priority when available, which is the expected pattern for GitHub Enterprise. No split needed—this is part of the broader GitHub integration work.

src/utils/providerProfiles.test.ts (1)

346-479: LGTM!

Also applies to: 1190-1218, 1261-1270

.env.example (1)

4-15: LGTM!

Also applies to: 143-156, 513-524

README.md (1)

127-129: LGTM!

Also applies to: 193-205, 223-289

🛑 Comments failed to post (2)
README.md (1)

108-108: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Avoid “securely stores credentials” here.

The profile flow appears to persist provider env values into .openclaude-profile.json, so this wording overstates the guarantee unless that path is encrypted or keychain-backed. Please rephrase to describe the storage location instead. (gitlawb.com)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@README.md` at line 108, The note on line 108 overstates the security
guarantee by claiming the `/provider` command "securely stores credentials" when
the actual storage mechanism is the `.openclaude-profile.json` file, which may
not be encrypted or keychain-backed. Replace the phrase "securely stores
credentials" with a more accurate description that specifies the credentials are
persisted to `.openclaude-profile.json` and avoid implying encryption or
advanced security measures unless that protection is actually implemented.
src/services/api/providerConfig.ts (1)

822-841: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

GHE base URL rewrite is skipped when only OPENAI_BASE_URL is set.

At Line 839, gheCopilotBaseUrl is derived only from githubEnterpriseEnvUrl. If rawBaseUrl is already a GHE host and GITHUB_ENTERPRISE_URL is unset, isGithubGhe becomes true but Line 893 cannot rewrite to .../api/copilot, so requests can be sent to the wrong base path.

Suggested fix
-  const gheUrl = githubEnterpriseEnvUrl
+  const gheUrl = getGithubEnterpriseUrl(rawBaseUrl)
   const githubEndpointType = isGithubMode
     ? (gheUrl && !rawBaseUrl
       ? 'ghe'
       : getGithubEndpointType(rawBaseUrl, { githubEnterpriseUrl: gheUrl }))
     : 'custom'
@@
-  const gheCopilotBaseUrl = gheUrl
+  const gheCopilotBaseUrl = gheUrl
     ? buildGithubEnterpriseCopilotBaseUrl(gheUrl)
     : undefined

Please also add a focused regression in src/services/api/providerConfig.test.ts for: GitHub mode + GHE OPENAI_BASE_URL set + no GITHUB_ENTERPRISE_URL, asserting baseUrl resolves to .../api/copilot.

As per coding guidelines, “Review provider routing, model selection, env precedence … with high scrutiny” and “Add or update tests when the change affects behavior.”

Also applies to: 893-900

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/services/api/providerConfig.ts` around lines 822 - 841, The
gheCopilotBaseUrl variable is only derived from githubEnterpriseEnvUrl (gheUrl),
but when isGithubGhe is true due to rawBaseUrl being set and
githubEnterpriseEnvUrl is unset, gheCopilotBaseUrl remains undefined. This
causes the base URL rewrite at lines 893-900 to fail. Fix this by also checking
if rawBaseUrl is a GHE host when gheUrl is undefined, and use
buildGithubEnterpriseCopilotBaseUrl with rawBaseUrl in that case to ensure
gheCopilotBaseUrl is properly set. Additionally, add a regression test in
src/services/api/providerConfig.test.ts covering the scenario where GitHub mode
is enabled with a GHE OPENAI_BASE_URL but no GITHUB_ENTERPRISE_URL, asserting
that the final baseUrl includes the .../api/copilot path.

Source: Coding guidelines

@chioarub chioarub dismissed stale reviews from jatmn and kevincodex1 via f5b628c June 18, 2026 07:58
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 18, 2026
@chioarub chioarub requested review from jatmn and kevincodex1 June 18, 2026 14:46

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. I do not see any actionable issues from my review.

@kevincodex1 LGTM

@kevincodex1 kevincodex1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kevincodex1 kevincodex1 merged commit b581bd9 into Gitlawb:main Jun 19, 2026
4 checks passed
@chioarub chioarub deleted the feat/zai-glm-5-2-thinking branch June 19, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants