feat: bump supercode-cli version to 0.1.86 and enhance hallucination guard:#228
Conversation
…guard: - Updated version in package.json to 0.1.86. - Implemented a hallucination guard in the agent runner to detect when the model claims actions without making tool calls. - Added new rules in prompts for refactoring callbacks to async/await for better coding practices.
|
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 update adds callback-to- ChangesAgent safeguards
Chat overlay rendering
Server release metadata
Estimated code review effort: 3 (Moderate) | ~20 minutes 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: 3
🤖 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/agent/prompts/build.txt`:
- Around line 36-37: Update the async/await migration guidance in
apps/supercode-cli/server/src/agent/prompts/build.txt lines 36-37 to explicitly
require an async function or Promise-returning contract and migration of all
callers to await or otherwise handle the Promise; preserve the instruction to
remove callbacks and let errors propagate. Apply the same complete migration
guidance to apps/supercode-cli/server/src/agent/prompts/general.txt lines 21-22.
In `@apps/supercode-cli/server/src/agent/runner.ts`:
- Around line 207-213: Update the action detection logic in the event-processing
block around lastStepHadActionClaim so it recognizes only affirmative completion
claims, not standalone verbs. Require the matched action verbs to appear in
claim patterns indicating the agent performed the action, and explicitly exclude
negated or hypothetical phrasing such as “could not,” “did not,” or “would.”
- Around line 105-118: Update the hallucination-guard branch in prepareStep to
preserve the existing step messages when injecting the system notice. Append the
notice to the current full message set rather than returning an object
containing only the new system message, while keeping the existing
lastStepHadActionClaim reset and notice content.
🪄 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: 18a390eb-ac54-44a3-b233-72a7d43f5c09
📒 Files selected for processing (5)
apps/supercode-cli/server/package.jsonapps/supercode-cli/server/src/agent/prompts/build.txtapps/supercode-cli/server/src/agent/prompts/general.txtapps/supercode-cli/server/src/agent/runner.tsapps/supercode-cli/server/src/cli/ai/chat/chat.ts
| - **When refactoring callbacks to async/await:** Remove ALL callback parameters and cb()/callback() calls. Use `return` for success values and let errors propagate naturally (or `throw`). The function signature must change from `(arg, cb)` to `(arg)`. Do NOT keep callbacks in any form — that defeats the purpose of async/await. | ||
|
|
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Align both prompt templates around a complete async migration.
Both rules remove callbacks without explicitly requiring an async/Promise contract or migrating callers, so agents can produce partial refactors that break existing call sites.
apps/supercode-cli/server/src/agent/prompts/build.txt#L36-L37: requireasync/Promise returns and caller updates.apps/supercode-cli/server/src/agent/prompts/general.txt#L21-L22: apply the same complete migration guidance.
📍 Affects 2 files
apps/supercode-cli/server/src/agent/prompts/build.txt#L36-L37(this comment)apps/supercode-cli/server/src/agent/prompts/general.txt#L21-L22
🤖 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/agent/prompts/build.txt` around lines 36 - 37,
Update the async/await migration guidance in
apps/supercode-cli/server/src/agent/prompts/build.txt lines 36-37 to explicitly
require an async function or Promise-returning contract and migration of all
callers to await or otherwise handle the Promise; preserve the instruction to
remove callbacks and let errors propagate. Apply the same complete migration
guidance to apps/supercode-cli/server/src/agent/prompts/general.txt lines 21-22.
| // Hallucination guard: previous step claimed actions but made no tool calls | ||
| if (lastStepHadActionClaim) { | ||
| lastStepHadActionClaim = false | ||
| return { | ||
| messages: [{ | ||
| role: "system" as const, | ||
| content: | ||
| "SYSTEM NOTICE: Your previous response claimed to have made changes " + | ||
| "(e.g., wrote, edited, refactored) but you did not call any tools. " + | ||
| "Do not describe changes — actually execute them by calling the appropriate " + | ||
| "tool (edit_file, write_file, run_command, etc.). Then summarize what you did.", | ||
| }], | ||
| } | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
rg -n '"ai"\s*:' apps/supercode-cli/server/package.json
find apps/supercode-cli/server -path '*/node_modules/ai/*' -type f \
\( -name '*.d.ts' -o -name '*.md' \) -print0 |
xargs -0 -r rg -n 'prepareStep|PrepareStepResult|messages'Repository: yashdev9274/supercli
Length of output: 183
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
printf '--- runner outline ---\n'
ast-grep outline apps/supercode-cli/server/src/agent/runner.ts || true
printf '\n--- runner relevant lines ---\n'
cat -n apps/supercode-cli/server/src/agent/runner.ts | sed -n '1,220p'
printf '\n--- lockfile ai package if present ---\n'
git ls-files | rg '(^|/)bun\.lockb$|(^|/)package-lock\.json$|(^|/)pnpm-lock\.yaml$|(^|/)yarn\.lock$' || true
if [ -f apps/supercode-cli/server/package-lock.json ]; then
jq -r '"ai"\? | select(.)' apps/supercode-cli/server/package-lock.json || true
fiRepository: yashdev9274/supercli
Length of output: 249
🌐 Web query:
ai-sdk Core streamText prepareStep callback messages parameter 6.0.195
💡 Result:
In AI SDK version 6.0.x (including 6.0.195), the prepareStep callback in streamText (and generateText) receives a messages parameter [1]. This parameter represents the messages that will be sent to the model for the current step, which by default is an array consisting of the initialMessages passed to the function followed by any accumulated responseMessages [2][1]. Key behavioral details for the messages parameter in AI SDK 6.x include: 1. Usage: You can use the messages parameter to access the current conversation state within the prepareStep callback [2][3]. 2. Overriding: If prepareStep returns a messages override, that override applies specifically to the current step [4][5]. Unlike in AI SDK 7+, where message overrides carry forward to subsequent steps by default [5], in AI SDK 6.x, the override is generally localized to the step for which it was returned [5]. 3. Context: The messages array is constructed dynamically at the start of each step before calling prepareStep [1]. If you are upgrading to or working with newer versions of the AI SDK (v7 and later), note that the behavior of prepareStep has been updated so that returning messages carries those overrides forward to all later steps [5]. To maintain compatibility or achieve specific historical behavior, newer versions also introduced initialMessages and responseMessages parameters to the prepareStep options to allow for precise manual reconstruction of the message history [6][5].
Citations:
- 1: https://cdn.jsdelivr.net/npm/ai@6.0.145/src/generate-text/stream-text.ts
- 2: https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling
- 3: vercel/ai@51f497d
- 4: https://ai-sdk.dev/v7/docs/reference/ai-sdk-core/stream-text
- 5: vercel/ai@31f69de
- 6: vercel/ai@eee1166
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "--- runner relevant lines ---"
cat -n apps/supercode-cli/server/src/agent/runner.ts | sed -n '1,220p'
echo
echo "--- package lock ai if present ---"
find apps/supercode-cli/server -maxdepth 3 \( -name 'package-lock.json' -o -name 'bun.lockb' -o -name 'pnpm-lock.yaml' -o -name 'yarn.lock' \) -print -exec sh -c 'echo "## $1"; case "$1" in *.json) jq -r ".packages.\"\".dependencies?.ai // \"\"" ;; *) rg -n "\"ai\"" "$1" || true ;; esac' sh {} \;Repository: yashdev9274/supercli
Length of output: 10303
🌐 Web query:
ai-sdk 6.0.195 streamText prepareStep implementation PrepareStepOverride messages
💡 Result:
In the Vercel AI SDK, the prepareStep callback is a function used to dynamically adjust settings such as the model, tool choices, active tools, instructions, and messages for each step in a multi-step generation loop [1][2][3]. The messages override logic in prepareStep has evolved in recent SDK versions (notably in AI SDK 7+). When you return a messages override from prepareStep, those messages now persist and serve as the base for all subsequent steps [4][2][3]. New assistant or tool response messages generated in the following steps are appended to this overridden message array [3]. The prepareStep function receives the following message-related parameters to help you manage state: - messages: Represents the current message state for the step. If you return an override here, this new array becomes the foundation for future steps [2][3]. - initialMessages: The original messages passed to the initial generateText or streamText call [2][5]. - responseMessages: The assistant and tool response messages accumulated from all previous steps [2][5]. Implementation Example: To maintain control over the message history (e.g., for compaction or cleaning), you can leverage these parameters [3]. If you want to replicate older behavior or ensure you are working from specific pieces of history, you can reconstruct the messages array manually inside your prepareStep function: const result = await streamText({ model: yourModel, tools: { weather }, prepareStep: ({ initialMessages, responseMessages }) => { // Example: Reconstruct messages to keep only specific parts, // or to perform compaction. return { messages: [...initialMessages,...responseMessages, // Add your logic to filter or modify messages here ], }; }, }); This pattern allows you to decide exactly what state is passed forward into the next iteration of the loop [3]. If you do not return a messages override, the SDK continues using the existing accumulated message state [2][3].
Citations:
- 1: https://ai-sdk.dev/v7/docs/reference/ai-sdk-core/stream-text
- 2: https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling
- 3: https://ai-sdk.dev/docs/agents/loop-control
- 4: vercel/ai@31f69de
- 5: vercel/ai@eee1166
🌐 Web query:
ai package 6.0.195 streamText source prepareStep messages override
💡 Result:
In the Vercel AI SDK, the prepareStep function allows you to customize the configuration of individual steps in a multi-step generation (e.g., when using maxSteps > 1) [1][2]. Regarding message overrides: 1. Current Behavior: If you return a messages override from prepareStep, those messages now carry forward as the base for subsequent steps [3][2]. This behavior was updated to be more intuitive, as previous versions of the SDK (such as AI SDK 6) only applied the override to the current step [3]. 2. Implementation Details: The prepareStep function receives the following relevant arguments: - initialMessages: The messages originally passed to streamText or generateText [4][2]. - responseMessages: The accumulated assistant and tool response messages so far [2]. - messages: The current full set of messages sent to the model for the current step [2]. 3. Maintaining Backward Compatibility (One-Step Overrides): If you need to maintain the older behavior where an override applies only to a single step, you can manually rebuild the messages within the prepareStep function by combining the initial and response messages, then applying your specific modification [3]. Example pattern for one-step-only modifications: prepareStep: ({ initialMessages, responseMessages }) => { return { messages: [...initialMessages,...responseMessages, // Add your one-step-only message changes here ], }; }, This approach ensures you have full control over the message history while leveraging the SDK's updated state handling [3][5].
Citations:
- 1: https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text
- 2: https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling
- 3: vercel/ai@31f69de
- 4: https://github.com/vercel/ai/blob/83877a1e/packages/ai/src/generate-text/prepare-step.ts
- 5:
prepareStepmessages-overriding is not preserved between steps vercel/ai#9631
🌐 Web query:
github packages ai 6.0.195 streamText.ts PrepareStepCallbackMessagesPrepareStepResult
💡 Result:
In the context of the Vercel AI SDK (specifically the ai package), PrepareStepResult is a type used within the prepareStep configuration option of streamText and generateText [1][2]. The term PrepareStepCallbackMessagesPrepareStepResult does not exist as a formal API name, type, or identifier in the AI SDK codebase; it appears to be a combined or misremembered reference to the prepareStep function and its return type, PrepareStepResult [1][3]. The prepareStep option is a function that allows you to provide custom settings for individual steps in a multi-step generation process (e.g., when tool calling is involved) [1][4]. The PrepareStepResult type defines the object that this function must return if you wish to override settings for the current step [1][3]. Key capabilities provided by the PrepareStepResult object include: - model: Optionally override the LanguageModel used for the step [1][3]. - toolChoice: Configure which tool the model must call [1][3]. - activeTools: Filter which tools are enabled for the step [1][3]. - instructions/system: Override instructions sent to the model [1][3]. - messages: Override the array of messages sent to the model for the current step [1][3]. - providerOptions: Pass provider-specific configuration [1][3]. The streamText.ts file manages the orchestration of these steps, calling prepareStep to determine the parameters (like stepMessages) before invoking the language model for each step [5][4]. If prepareStep returns undefined, the SDK uses the settings from the initial streamText configuration [4].
Citations:
- 1: https://github.com/vercel/ai/blob/83877a1e/packages/ai/src/generate-text/prepare-step.ts
- 2: https://ai-sdk.dev/v7/docs/reference/ai-sdk-core/stream-text
- 3: https://github.com/vercel/ai/blob/a23b6767/packages/ai/src/generate-text/prepare-step.ts
- 4: https://cdn.jsdelivr.net/npm/ai@6.0.116/src/generate-text/stream-text.ts
- 5: https://github.com/vercel/ai/blob/08cdf6ae/packages/ai/src/generate-text/stream-text.ts
🌐 Web query:
registry.npmjs.org/ai 6.0.195 tarball source
💡 Result:
Version 6.0.195 of the ai npm package is a release of the Vercel AI SDK, an open-source TypeScript toolkit for building AI-powered applications [1][2]. This version was published on June 2, 2026 [1]. The source code for this version is hosted within the official Vercel AI SDK repository on GitHub (vercel/ai) [1][3]. The specific changes for version 6.0.195 involved a dependency update to @ai-sdk/gateway version 3.0.123 [1][4]. Users can verify or download the package directly from the npm registry [5][6]. As of July 2026, the AI SDK has evolved significantly, with newer releases (such as the 7.x series) now available [5][7]. Developers are generally encouraged to use the latest stable version unless specific compatibility requirements necessitate an older release [7].
Citations:
- 1: https://github.com/vercel/ai/releases/tag/ai%406.0.195
- 2: https://github.com/vercel/ai
- 3: vercel/ai@5b183c0
- 4: https://github.com/vercel/ai/blob/ai@6.0.196/packages/ai/CHANGELOG.md
- 5: https://registry.npmjs.org/ai
- 6: https://www.npmjs.com/package/ai
- 7: https://www.npmjs.com/package/ai?activeTab=versions
🏁 Script executed:
#!/bin/bash
set -euo pipefail
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
curl -fsSL -o "$tmp/ai-6.0.195.tgz" https://registry.npmjs.org/ai/-/ai-6.0.195.tgz
tar -xzf "$tmp/ai-6.0.195.tgz" -C "$tmp"
echo "--- package version ---"
node -e 'const p=require("$tmp/package/package.json"); console.log(p.version)' sh "$tmp"
echo
echo "--- stream-text prepare step relevant snippets ---"
rg -n "prepareStep|stepMessages|messages.*override|initialMessages|responseMessages" "$tmp/package/src" "$tmp/package/dist"
echo
echo "--- stream-text.ts excerpt ---"
cat -n "$tmp/package/src/generate-text/stream-text.ts" | sed -n '1,260p'
echo
echo "--- generate-text.ts excerpt ---"
cat -n "$tmp/package/src/generate-text/generate-text.ts" | sed -n '1,260p'
echo
echo "--- prepare-step.ts excerpt ---"
cat -n "$tmp/package/src/generate-text/prepare-step.ts" | sed -n '1,260p'
echo
echo "--- build-messages excerpt if present ---"
find "$tmp/package/src" -name 'build-messages.ts' -o -name '*message*' | xargs -r rg -n "function|export|initialMessages|responseMessages" -C 3Repository: yashdev9274/supercli
Length of output: 1052
🏁 Script executed:
#!/bin/bash
set -euo pipefail
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
curl -fsSL -o "$tmp/ai-6.0.195.tgz" https://registry.npmjs.org/ai/-/ai-6.0.195.tgz
version="$(node -e "const p=require('./package/package.json'); console.log(p.version)" "$tmp")"
echo "--- package version: $version"
echo
echo "--- prepare step implementation ---"
cat -n "$tmp/package/src/generate-text/prepare-step.ts" | sed -n '1,280p'
echo
echo "--- stream text relevant message construction ---"
cat -n "$tmp/package/src/generate-text/stream-text.ts" | sed -n '1,340p'
echo
echo "--- generate text relevant message construction ---"
cat -n "$tmp/package/src/generate-text/generate-text.ts" | sed -n '1,340p'
echo
echo "--- exported types around PrepareStepResult if present ---"
rg -n "PrepareStepResult|MessagesPrepareStepResult|messages:.*override|stepMessages" "$tmp/package/src/generate-text" "$tmp/package/src/generate-text/prepare-step.ts" -C 2Repository: yashdev9274/supercli
Length of output: 1025
🏁 Script executed:
#!/bin/bash
set -euo pipefail
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
pkg="$tmp/package"
mkdir -p "$pkg"
curl -fsSL -o "$pkg/ai-6.0.195.tgz" https://registry.npmjs.org/ai/-/ai-6.0.195.tgz
tar -xzf "$pkg/ai-6.0.195.tgz" -C "$pkg"
echo "--- package version ---"
node -e 'const p=require(process.argv[1]); console.log(p.version)' "$pkg/package/package.json"
echo
echo "--- prepare-step.ts ---"
cat -n "$pkg/package/src/generate-text/prepare-step.ts" | sed -n '1,280p'
echo
echo "--- stream-text.ts ---"
cat -n "$pkg/package/src/generate-text/stream-text.ts" | sed -n '1,340p'
echo
echo "--- generate-text.ts ---"
cat -n "$pkg/package/src/generate-text/generate-text.ts" | sed -n '1,340p'
echo
echo "--- build-messages.ts candidates ---"
find "$pkg/package/src" -maxdepth 2 -type f | sort | xargs rg -n "build.*messages|initialMessages|responseMessages|Messages" -C 2 | head -n 220Repository: yashdev9274/supercli
Length of output: 50376
🏁 Script executed:
#!/bin/bash
set -euo pipefail
pkg="$(mktemp -d)"
tar -xzf <(curl -fsSL https://registry.npmjs.org/ai/-/ai-6.0.195.tgz) -C "$pkg"
echo "--- streamText loop/message construction snippets ---"
rg -n "prepareStep|stepMessages|messages =|responseMessages|previousStep|current messages|convertToLanguageModelPrompt|await .*prepareStep|const .*messages|response-messages" "$pkg/package/src/generate-text/stream-text.ts" -C 4
echo
echo "--- generated exact prepareStep call loop ---"
python3 - <<'PY'
from pathlib import Path
p = Path("$pkg/package/src/generate-text/stream-text.ts").with_name(Path("$pkg/package/src/generate-text/stream-text.ts").name)
# use shell var by reading literal file pattern passed via heredoc? not needed
PY
sed -n '480,720p' "$pkg/package/src/generate-text/stream-text.ts"Repository: yashdev9274/supercli
Length of output: 345
🏁 Script executed:
#!/bin/bash
set -euo pipefail
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
pkg="$tmp/package"
curl -fsSL -o "$pkg/ai.tgz" https://registry.npmjs.org/ai/-/ai-6.0.195.tgz
tar -xzf "$pkg/ai.tgz" -C "$pkg"
echo "--- streamText.js/TS exact message loop around step generation ---"
sed -n '560,740p' "$pkg/package/src/generate-text/stream-text.ts"
echo
echo "--- generateText.js exact message loop around step generation ---"
sed -n '520,720p' "$pkg/package/src/generate-text/generate-text.ts"Repository: yashdev9274/supercli
Length of output: 209
🏁 Script executed:
#!/bin/bash
set -euo pipefail
tmp="$(mktemp -d)"
curl -L -o "$tmp/ai.tgz" https://registry.npmjs.org/ai/-/ai-6.0.195.tgz || { echo "curl failed"; exit 1; }
tar -xzf "$tmp/ai.tgz" -C "$tmp"
pkg="$tmp/package"
echo "--- streamText line count ---"
wc -l "$pkg/package/src/generate-text/stream-text.ts"
echo "--- streamText exact message loop snippets ---"
rg -n "prepareStep|messages|responseMessages|previousStep|asArray" "$pkg/package/src/generate-text/stream-text.ts" -C 5
echo
echo "--- surrounding streamText lines 560-710 ---"
cat -n "$pkg/package/src/generate-text/stream-text.ts" | sed -n '560,710p'
echo
echo "--- surrounding generateText lines 520-710 ---"
cat -n "$pkg/package/src/generate-text/generate-text.ts" | sed -n '520,710p'Repository: yashdev9274/supercli
Length of output: 605
🏁 Script executed:
#!/bin/bash
set -euo pipefail
tmp="$(mktemp -d)"
curl -L -o "$tmp/ai.tgz" https://registry.npmjs.org/ai/-/ai-6.0.195.tgz || { echo "curl failed"; exit 1; }
tar -xzf "$tmp/ai.tgz" -C "$tmp"
pkg="$tmp/package/package"
echo "--- top dir ---"
find "$pkg" -maxdepth 3 -type f | sort | head -n 40
echo
echo "--- streamText if present ---"
find "$pkg" -name 'stream-text.ts' -type f -print
fi
file="$(find "$pkg" -path '*generate-text/stream-text.ts' -type f | head -n 1)"
if [ -z "$file" ]; then
file="$(find "$pkg" -name 'stream-text.ts' -type f | head -n 1)"
fi
if [ -n "$file" ]; then
echo "--- streamText line count ---"
wc -l "$file"
echo
echo "--- streamText prepareStep and message construction ---"
rg -n "prepareStep|messages|responseMessages|previousStep|asArray|convertToLanguageModelPrompt" "$file" -C 6
echo
echo "--- streamText lines 560-710 ---"
cat -n "$file" | sed -n '560,710p'
fi
echo
echo "--- generateText if present ---"
file2="$(find "$pkg" -path '*generate-text/generate-text.ts' -type f | head -n 1)"
if [ -z "$file2" ]; then
file2="$(find "$pkg" -name 'generate-text.ts' -type f | head -n 1)"
fi
if [ -n "$file2" ]; then
echo "--- generateText lines 520-710 ---"
cat -n "$file2" | sed -n '520,710p'
fiRepository: yashdev9274/supercli
Length of output: 562
🏁 Script executed:
#!/bin/bash
set -euo pipefail
tmp="$(mktemp -d)"
tar -xzf <(curl -L https://registry.npmjs.org/ai/-/ai-6.0.195.tgz) -C "$tmp"
pkg="$tmp/package"
echo "--- package files with generate ---"
find "$pkg" -name 'stream-text.ts' -o -name 'generate-text.ts' -o -name 'step-result.ts' | sort
echo
echo "--- stream-text.ts -- streamText -- prepareStep -- messages loop"
rg -n "prepareStep|messages|responseMessages|previousStep|asArray|stepMessages|responseMessagesForStep|current.*messages" "$pkg/src/generate-text/stream-text.ts" "$pkg/src/generate-text/generate-text.ts" -C 5
echo
echo "--- stream-text.ts lines 580-730 ---"
cat -n "$pkg/src/generate-text/stream-text.ts" | sed -n '580,730p'
echo
echo "--- generate-text.ts lines 540-720 ---"
cat -n "$pkg/src/generate-text/generate-text.ts" | sed -n '540,720p'Repository: yashdev9274/supercli
Length of output: 345
🌐 Web query:
site:github.com/vercel/ai packages/ai/src/generate-text/stream-text.ts ai@6.0.195 prepareStep messages
💡 Result:
In the Vercel AI SDK, the prepareStep callback is an optional function used within streamText (and generateText) to customize settings or modify inputs for individual steps of an agentic loop [1][2][3]. As of version 6.0.195 and surrounding recent updates (e.g., in May 2026), the prepareStep function receives several parameters to allow for granular control over the step's execution [4]: - model: The model currently being used for the step [3]. - stepNumber: The current step index [3]. - steps: An array of steps that have been executed so far [3]. - messages: The current sequence of messages that will be sent to the model for this step [3]. - initialMessages: The initial message sequence provided at the start of the interaction [4]. - responseMessages: The accumulated response messages from previous steps [4]. - experimental_context: Optional runtime context [3]. By returning an object from prepareStep, you can override settings for the current step, such as providing a different model, adjusting activeTools, or modifying the messages array itself [3]. This is particularly useful for techniques like prompt compression, where you can truncate or summarize conversation history for longer agentic loops [3]. If prepareStep returns undefined, the default settings from the outer scope are used [2][3]. The logic in packages/ai/src/generate-text/stream-text.ts uses prepareStep to resolve the final prompt structure—combining the system prompt and messages—before invoking the language model for that specific step [1][2]. Recent updates have explicitly separated initialMessages and responseMessages to provide developers with more explicit control over conversation state management across multiple steps [4][5].
Citations:
- 1: https://github.com/vercel/ai/blob/67f7e765458500102d6a4e60a4687692b0d03efd/packages/ai/src/generate-text/stream-text.ts
- 2: https://github.com/vercel/ai/blob/08cdf6ae/packages/ai/src/generate-text/stream-text.ts
- 3: https://github.com/vercel/ai/blob/08cdf6ae/content/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx
- 4: vercel/ai@eee1166
- 5: vercel/ai@31f69de
Preserve the conversation when injecting the notice.
prepareStep receives the full step message set, so returning only the system notice replaces all prior messages for that retry. Append the notice to the current step messages instead.
🤖 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/agent/runner.ts` around lines 105 - 118, Update
the hallucination-guard branch in prepareStep to preserve the existing step
messages when injecting the system notice. Append the notice to the current full
message set rather than returning an object containing only the new system
message, while keeping the existing lastStepHadActionClaim reset and notice
content.
| // Track whether this step had tool calls for the hallucination guard | ||
| lastStepHadToolCalls = (event.toolCalls?.length ?? 0) > 0 | ||
| lastStepHadActionClaim = false | ||
| if (!lastStepHadToolCalls && event.text) { | ||
| const actionClaimRe = /\b(wrote|updated|added|created|ran|executed|fixed|refactored|removed|deleted|installed|modified|edited|applied|saved|generated|wired|hooked)\b/i | ||
| lastStepHadActionClaim = actionClaimRe.test(event.text) | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Restrict action detection to affirmative completion claims.
The verb-only regex also matches negated or hypothetical text such as “I could not run the tests” or “I did not modify the file,” causing a false corrective notice and an unnecessary extra model step. Match affirmative claim patterns and explicitly exclude negations.
🤖 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/agent/runner.ts` around lines 207 - 213, Update
the action detection logic in the event-processing block around
lastStepHadActionClaim so it recognizes only affirmative completion claims, not
standalone verbs. Require the matched action verbs to appear in claim patterns
indicating the agent performed the action, and explicitly exclude negated or
hypothetical phrasing such as “could not,” “did not,” or “would.”
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
Improvements
async/await.Release