feat: update supercode-cli to version 0.1.85 and enhance request handling:#227
Conversation
…ling: - Bumped version in package.json to 0.1.85. - Introduced JSON body size limit for requests, configurable via environment variable. - Added error handling middleware to respond with appropriate messages for oversized requests. - Improved progress display messaging in AI response to provide clearer user updates. - Enhanced diff functionality to include line numbers and better context visualization for changes.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
WalkthroughThe CLI updates streamed response fallback handling, skill cleanup, thought-chain and tool-snapshot rendering, server JSON body limits, and the package version. ChangesCLI chat and transcript rendering
JSON request body limits
Package release metadata
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant ChatLoop
participant streamAIResponse
participant MarkdownStream
participant SkillContext
ChatLoop->>streamAIResponse: stream chat response
streamAIResponse->>MarkdownStream: setFallback(fullResponse)
MarkdownStream-->>ChatLoop: render buffered or fallback content
ChatLoop->>SkillContext: clearSkill()
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/supercode-cli/server/src/cli/ai/chat/chat.ts (1)
2126-2151: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick winPersist assistant replies for skill/message slash turns.
The
result.type === "message"branch streamsaiResultbut skipsaddMessage(conversation.id, "assistant", aiResult.content), so multi-turn/skill <message>conversations keep the user prompt in history but drop the assistant response. Add the same persistence as the main turn path, handlingabortedseparately if needed.🤖 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 `@apps/supercode-cli/server/src/cli/ai/chat/chat.ts` around lines 2126 - 2151, In the result.type === "message" branch, persist the streamed assistant reply by adding aiResult.content through addMessage after streamAIResponse succeeds, matching the main turn path. Handle aborted responses separately so incomplete replies are not persisted, while preserving the existing output, footer rendering, and clearSkill cleanup.
🤖 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 `@apps/supercode-cli/server/src/index.ts`:
- Line 68: Update the SUPERCODE_JSON_BODY_LIMIT configuration near
JSON_BODY_LIMIT to distinguish missing or empty values from malformed non-empty
values: default only when unset or empty, otherwise parse and validate the value
using the same bytes-compatible rules before constructing express.json. Fail
startup with a clear configuration error when validation fails, rather than
allowing middleware construction to throw.
---
Outside diff comments:
In `@apps/supercode-cli/server/src/cli/ai/chat/chat.ts`:
- Around line 2126-2151: In the result.type === "message" branch, persist the
streamed assistant reply by adding aiResult.content through addMessage after
streamAIResponse succeeds, matching the main turn path. Handle aborted responses
separately so incomplete replies are not persisted, while preserving the
existing output, footer rendering, and clearSkill cleanup.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d1fc7547-1d15-4529-b605-7da7e2f2e352
📒 Files selected for processing (6)
apps/supercode-cli/server/package.jsonapps/supercode-cli/server/src/cli/ai/chat/chat.tsapps/supercode-cli/server/src/cli/ai/chat/thinking.tsapps/supercode-cli/server/src/cli/utils/markdown-stream.tsapps/supercode-cli/server/src/cli/utils/tool-snapshot.tsapps/supercode-cli/server/src/index.ts
| "minimax-m3", | ||
| "hy3", | ||
| ]) | ||
| const JSON_BODY_LIMIT = process.env.SUPERCODE_JSON_BODY_LIMIT || "10mb" |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Locate target file"
fd -a 'index\.ts$' . | sed 's#^\./##' | rg 'apps/supercode-cli/server/src/index\.ts|index\.ts$' || true
echo
echo "Relevant sections"
sed -n '1,150p' apps/supercode-cli/server/src/index.ts
echo
echo "Find package versions/imports"
rg -n '"express"|body-parser|`@types/express`|json-body-limit|SUPERCODE_JSON_BODY_LIMIT' -S .
echo
echo "List package files"
git ls-files | rg '(^|/)package\.json$|bun\.lock|bun\.lockb$|pnpm-lock|yarn\.lock' || true
echo
echo "Show dependency snippets"
python3 - <<'PY'
from pathlib import Path
for p in [Path('package.json'), Path('apps/supercode-cli/server/package.json')]:
if p.exists():
import json
print(f'--- {p} ---')
data=json.loads(p.read_text())
print(json.dumps({k:data.get(k) for k in ('dependencies','devDependencies') if k in data}, indent=2, sort_keys=True))
PYRepository: yashdev9274/supercli
Length of output: 19086
🌐 Web query:
Express body-parser JSON limit option bytes lib source malformed limit value parse limit throw
💡 Result:
In the Express body-parser middleware, the limit option controls the maximum request body size [1][2]. If the provided limit is a number, it is interpreted directly as the number of bytes [1][3]. If the limit is a string, it is passed to the bytes library for parsing (e.g., '100kb', '1mb') [1][2][3]. If a malformed string is provided to the limit option, the bytes library will typically throw an error during the initialization of the middleware [1][2][3]. Because this initialization happens when the middleware is configured (usually at application startup), an invalid limit value will cause the application to crash or fail to start, rather than throwing an error during individual request processing [1][3]. Regarding other related errors: - If a request body exceeds the configured limit, the middleware will throw an error with the status code 413 ('entity.too.large') [1][2][4]. - If a request is considered malformed because the 'Content-Length' header does not match the actual received body size, the middleware throws an error with the status code 400 ('request.size.invalid') [1][2][5]. - Errors encountered during JSON parsing (e.g., invalid JSON syntax) also typically result in a 400 'Bad Request' status code [6].
Citations:
- 1: https://expressjs.com/en/resources/middleware/body-parser/
- 2: https://github.com/expressjs/body-parser/blob/b53363c79edc01ebaf14f4e9f1dace62361b7d96/README.md
- 3: https://deepwiki.com/expressjs/body-parser/4-configuration-options
- 4: https://github.com/expressjs/expressjs.com/blob/gh-pages/_includes/readmes/body-parser.md
- 5: https://docsearch-expressjs.netlify.app/en/resources/middleware/body-parser
- 6: JSON.parse error should not propagate down the middleware chain expressjs/body-parser#567
🌐 Web query:
Express 5.2 json middleware raw-body limit option malformed limit source
💡 Result:
In Express 5 (including version 5.2), the express.json middleware—which internally uses the raw-body package—handles request body size constraints through the limit option [1][2][3]. When encountering issues related to limits or malformed requests, Express distinguishes between two primary error types based on the raw-body library's behavior [4][5]: 1. entity.too.large (Status 413): This occurs when the request body size exceeds the configured limit option [6][4]. The error object includes properties such as limit (the byte limit) and length (the actual size of the request body) [6][5]. 2. request.size.invalid (Status 400): This occurs when the actual size of the request stream does not match the value provided in the Content-Length header [6][4]. This is typically indicative of a malformed request, often caused when the Content-Length header was calculated based on character count rather than byte count [6][4]. To handle these errors effectively, it is recommended to implement a custom error-handling middleware with four parameters (err, req, res, next) [2]. This allows you to differentiate the error type using the err.type property and respond with appropriate status codes (413 for size limits or 400 for malformed/mismatched lengths) instead of exposing default stack traces [2]. The limit option itself defaults to '100kb' if not specified and accepts either a number (bytes) or a string compatible with the bytes library [6][3].
Citations:
- 1: https://thecodersblog.com/customizing-json-payload-limits-express-js/
- 2: https://jsonic.io/guides/json-in-express
- 3: https://devdocs.io/express/
- 4: https://github.com/expressjs/body-parser/blob/2.x-standard/README.md
- 5: https://registry.npmjs.org/raw-body
- 6: https://expressjs.com/en/resources/middleware/body-parser/
🏁 Script executed:
#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
p = Path("apps/supercode-cli/server/node_modules/express")
if not p.exists():
print("node_modules/express not present")
else:
files = list(p.glob("**/*.js"))
for f in files:
text = f.read_text(errors="ignore")
if "rawBody" in text and ('limit' in text):
print(f"--- {f.relative_to(Path.cwd())} ---")
for i, line in enumerate(text.splitlines(), 1):
if "rawBody" in line or "limit" in line or "body" in line.lower():
if 90 <= i <= 170 or "rawBody" in line or "limit" in line:
print(f"{i}: {line}")
PY
node - <<'JS'
try {
const bytesLib = require('bytes');
for (const value of ['notalimit', 'abc123mb', '100', 1024]) {
try {
console.log(`${JSON.stringify(value)} -> ${JSON.stringify(bytesLib(value))}`);
} catch (err) {
console.error(`${JSON.stringify(value)} -> ${err.name}: ${err.message}`);
}
}
} catch (err) {
console.log(`bytes module unavailable: ${err.name}: ${err.message}`);
}
try {
const express = require('express');
const app = express.default();
for (const value of ['abc', '10mb', 1024]) {
let ok = true;
try { app.use(express.json({ limit: value })); }
catch (err) { ok = false; console.error(`express.json limit ${JSON.stringify(value)} INIT ERROR ${err.name}: ${err.message}`); }
if (ok) console.log(`express.json limit ${JSON.stringify(value)} initialized successfully`);
}
} catch (err) {
console.log(`express module unavailable: ${err.name}: ${err.message}`);
}
JSRepository: yashdev9274/supercli
Length of output: 403
🌐 Web query:
raw-body JavaScript limit option string parse limit undefined throws Error bytes
💡 Result:
The raw-body package in JavaScript uses the limit option to define the maximum size of a request body in bytes [1][2]. When this limit is exceeded, raw-body explicitly throws an error with a 413 (Payload Too Large) status code and the error type 'entity.too.large' [3][2][4]. Regarding the behavior when the limit is undefined, raw-body does not typically throw a 413 error unless a limit is configured. However, if you are experiencing an error involving string parsing and limits (such as 'ERR_STRING_TOO_LONG'), this is often a separate limitation of the V8 JavaScript engine [5]. V8 imposes a hard limit on the maximum length of a string (typically around 512 MB, depending on the version and environment), which is independent of the raw-body package [5]. If the data being processed exceeds this V8 limit, the environment will throw an error regardless of whether a limit option was set in raw-body [5]. In summary: 1. If the error is a 413 'entity.too.large', it is caused by the raw-body limit option being configured and exceeded [3][6]. 2. If the error is related to string size (e.g., 'ERR_STRING_TOO_LONG'), it is likely a V8 engine memory limitation, not a raw-body specific configuration error [5].
Citations:
- 1: https://www.npmjs.com/package/raw-body
- 2: https://github.com/stream-utils/raw-body
- 3: https://registry.npmjs.org/raw-body
- 4: https://npmx.dev/package/raw-body/v/%5E3.0.2
- 5: Can't parse JSON response exceeding 512 MB nodejs/undici#4295
- 6: https://github.com/expressjs/body-parser
🌐 Web query:
bytes JavaScript parse "abc" throws Error invalid unit
💡 Result:
The error message "invalid unit" or similar validation failures when parsing byte strings in JavaScript typically occurs when using popular utility libraries like bytes or related packages designed to convert human-readable strings (e.g., "1KB") into numeric byte values [1][2][3][4]. When you pass a string like "abc" to these functions, it fails because the libraries expect a numeric component followed by a recognized unit [2][3][4]. 1. Why it throws an error: These libraries generally use regular expressions to parse the input string. They expect a specific format: a number (e.g., "1", "1.5") followed by a valid unit (e.g., "KB", "MB", "GB", "KiB") [3][4]. When the input is "abc", there is no numeric component, or the "unit" part cannot be parsed as a known scale, triggering an error or returning null/undefined [2][3][4]. 2. Typical Library Behavior: - Some libraries, such as @jsxx/bytes, are designed to throw an explicit Error when the input string format is invalid, citing issues like "Invalid byte string" or "Invalid format" [1][2]. - Other libraries, like format-byte-size, are designed to be safer by returning null or undefined instead of throwing an error when provided with unparseable inputs like "abc" [3][4]. 3. Troubleshooting: If your code is throwing an error: - Ensure the input is a valid string containing both a number and a unit (e.g., "100MB") [2][3]. - Wrap the call in a try...catch block if the library is known to throw errors [2]. - Verify which specific "bytes" library you are using, as behaviors regarding error handling (throwing vs. returning null) vary between implementations [1][3][4]. If you are using a library named exactly bytes (e.g., npm install bytes), it is commonly used to parse strings like "1kb" or "10mb". If you pass "abc" to a strict parser, it will fail because it cannot identify the multiplier associated with the unit [2]. Always check your package.json to identify the specific library documentation for your project [3][4].
Citations:
- 1: https://www.npmjs.com/package/@jsxx/bytes
- 2: https://registry.npmjs.org/@jsxx/bytes
- 3: https://registry.npmjs.org/format-byte-size
- 4: https://cdn.jsdelivr.net/npm/@wener/utils@1.1.58/src/strings/bytes.test.ts
Validate SUPERCODE_JSON_BODY_LIMIT before constructing the JSON parser.
express.json({ limit }) accepts byte counts or bytes-compatible strings like 10mb; any non-empty malformed value such as abc will fail while configuring the middleware. Fall back to 10mb only for missing/empty values, otherwise parse and validate the configured limit at startup with a clear config error.
🧰 Tools
🪛 ast-grep (0.44.1)
[warning] 68-68: Express application should use Helmet
Context: express()
Note: [CWE-693] Protection Mechanism Failure (Express app without Helmet security headers).
(missing-helmet-typescript)
🤖 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 `@apps/supercode-cli/server/src/index.ts` at line 68, Update the
SUPERCODE_JSON_BODY_LIMIT configuration near JSON_BODY_LIMIT to distinguish
missing or empty values from malformed non-empty values: default only when unset
or empty, otherwise parse and validate the value using the same bytes-compatible
rules before constructing express.json. Fail startup with a clear configuration
error when validation fails, rather than allowing middleware construction to
throw.
Description
Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes.
bun testpassesbun run typecheckpassesbun run lintpasses (if applicable)Checklist:
Summary by CodeRabbit
New Features
Bug Fixes