Skip to content

Conversation

@Seonfx
Copy link

@Seonfx Seonfx commented Jan 16, 2026

Summary

Fixes spec generation failure when using custom API endpoints (e.g., GLM proxy) that don't support structured output. The AI returns JSON instead of XML, but the fallback parser only looked for XML tags.

Root Cause

When ANTHROPIC_BASE_URL is set to a custom endpoint:

  1. Structured output (json_schema) is disabled (correct - custom endpoints may not support it)
  2. AI returns plain JSON in markdown code blocks instead of XML
  3. The fallback parser only searched for <project_specification> XML tags
  4. After JSON extraction was added, escapeXml() crashed on undefined/null values

Changes

apps/server/src/lib/app-spec-format.ts

  • Fixed escapeXml() to handle undefined/null values gracefully (converts to empty string)
  • Added String() wrapper for type safety

apps/server/src/routes/app-spec/generate-spec.ts

  • Added JSON extraction fallback when XML tags aren't found
  • Reuses existing extractJson() utility (already used for Cursor models)
  • Converts extracted JSON to XML using specToXml()

Related Issue

Closes #510

Testing

  • Verified spec generation with GLM proxy endpoint
  • Tested AI responses with missing optional fields (null/undefined values)
  • Code follows project style guidelines

🤖 Generated with Claude Code

Fixes spec generation failure when using custom API endpoints (e.g., GLM proxy)
that don't support structured output. The AI returns JSON instead of XML, but
the fallback parser only looked for XML tags.

Changes:
- escapeXml: Handle undefined/null values gracefully (converts to empty string)
- generate-spec: Add JSON extraction fallback when XML tags aren't found
  - Reuses existing extractJson() utility (already used for Cursor models)
  - Converts extracted JSON to XML using specToXml()

Closes AutoMaker-Org#510

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Jan 16, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.


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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Seonfx, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a critical fix for spec generation failures that occur when using custom AI API endpoints, such as GLM proxy, which may return plain JSON instead of the expected XML. It enhances the system's robustness by adding a JSON extraction fallback and converting it to XML, while also improving the escapeXml utility to handle undefined and null values gracefully.

Highlights

  • Robust XML Escaping: The escapeXml function now gracefully handles undefined and null inputs, preventing crashes and ensuring type safety by converting them to empty strings.
  • JSON Fallback for Spec Generation: Implemented a new fallback mechanism in the spec generation process to extract JSON from AI responses when the expected XML structure is not found, particularly useful for custom API endpoints.
  • JSON to XML Conversion: Successfully converts the extracted JSON into the required XML format using the specToXml() utility, ensuring compatibility with existing systems.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a helpful fallback mechanism for spec generation, allowing it to handle JSON responses from custom API endpoints that don't produce the expected XML. The changes are logical and well-structured. I've made a couple of suggestions:

  1. In app-spec-format.ts, I've proposed a more concise way to handle null and undefined values in escapeXml.
  2. More importantly, in generate-spec.ts, I've identified a potential runtime error where specToXml could crash if the extracted JSON doesn't match the SpecOutput schema. I've suggested adding a validation step to prevent this, making the new fallback logic more robust.

These changes will improve code quality and prevent potential crashes. Otherwise, the implementation looks solid.

logger.warn('⚠️ No XML tags found, attempting JSON extraction...');
const extractedJson = extractJson<SpecOutput>(responseText, { logger });

if (extractedJson) {
Copy link
Contributor

Choose a reason for hiding this comment

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

high

While extractJson successfully parses a JSON object, it doesn't validate its structure against the SpecOutput type. This could lead to a runtime error in specToXml if a required array property (like technology_stack) is missing, as it would attempt to call .map on undefined.

To prevent this, you should add validation to ensure the extracted JSON conforms to the expected SpecOutput structure before passing it to specToXml. A simple check for the presence and type of required fields would make this fallback much more robust.

Suggested change
if (extractedJson) {
if (extractedJson &&
typeof extractedJson.project_name === 'string' &&
typeof extractedJson.overview === 'string' &&
Array.isArray(extractedJson.technology_stack) &&
Array.isArray(extractedJson.core_capabilities) &&
Array.isArray(extractedJson.implemented_features)) {

Comment on lines 17 to 20
if (str === undefined || str === null) {
return '';
}
return String(str)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For better conciseness and to leverage TypeScript's type narrowing, you can simplify this check. Using str == null checks for both undefined and null. After this check, TypeScript knows str is a string, so the String() wrapper is not necessary.

Suggested change
if (str === undefined || str === null) {
return '';
}
return String(str)
if (str == null) {
return '';
}
return str

@Shironex
Copy link
Collaborator

If u could adress pr comments before i review it

@Shironex Shironex added Bug Something isn't working waiting-on-author Waiting on the PR author to review and address applicable automated review comments. labels Jan 16, 2026
- Simplify escapeXml() using 'str == null' check (type narrowing)
- Add validation for extracted JSON before passing to specToXml()
- Prevents runtime errors when JSON doesn't match SpecOutput schema

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@Seonfx
Copy link
Author

Seonfx commented Jan 16, 2026

If u could adress pr comments before i review it

done.

@Shironex Shironex merged commit 9819d2e into AutoMaker-Org:v0.12.0rc Jan 16, 2026
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working waiting-on-author Waiting on the PR author to review and address applicable automated review comments.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants