Skip to content

Supersede ACE - #346

Draft
vemvcs wants to merge 40 commits into
mainfrom
agentic-ace-v2
Draft

vemvcs wants to merge 40 commits into
mainfrom
agentic-ace-v2

Conversation

@vemvcs

@vemvcs vemvcs commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Commits:

feat: integrate cs-agent for refactoring

Replace the old ACE backend with the local cs-agent binary for
refactoring operations. This eliminates dependency on the ACE
backend service while keeping the existing CWF webview UI.

  • Add AgentRefactoringService to invoke cs-agent binary
  • Add agent types and configuration modules
  • Add VS Code settings for agent model and AWS config
  • Add platform-specific package targets in Makefile
  • Update .vscodeignore to include bin/ directory
  • Add unit tests for mapping logic and config building
  • Add integration test for real binary invocation

refactor: rename ACE to CodeScene Refactoring Agent

Aligns with the agentic-ace branch reference implementation:

  • Remove agentModel, awsProfile, awsRegion settings
    (agent reads its own config)
  • Update user-facing strings from "CodeScene ACE"
    to "CodeScene Agent" or "CodeScene Refactoring Agent"
  • Simplify agent config to only pass token and plugins

fix: handle open-settings message in ACE acknowledgement panel

Clicking "Extension Settings" in the ACE acknowledgement panel was
logging an error because the panel didn't have a handler for the
open-settings message type. Reuse the existing handleOpenSettings
function from cwf-message-handlers.

fix: spawn refactoring agent with git repository root as cwd

The agent was being spawned with a temp directory as cwd, causing
"not inside a git repository" errors. Use the git repo root so the
agent can access the entire project and run git commands.

fix: add Amazon Bedrock provider config for refactoring agent

The agent was failing with "UnknownError" because the opencode_config
with Amazon Bedrock provider settings was missing from the agent config.
Also adds the --model argument to explicitly request the Bedrock model.

fix: handle whole_file change type in agent output

The agent outputs whole_file_content instead of replacements when
change_type is "whole_file". Also fixes the integration test to
initialize a git repo and adds assertions verifying the agent
writes the expected output file.

chore: remove debug log statements

feat: forward agent stdout to CWF progress widget

Stream progress messages from the refactoring agent binary to the
loading view instead of showing hardcoded rotating messages. The
most recent stdout line is displayed, with newer lines replacing
older ones.

chore: gitignore bin/cs-agent

chore: add updatecwf target for local CWF development

Automatically build and copy CWF from ../cs-webview when running
as vemv, otherwise download from GitHub releases. Make build
depend on updatecwf to ensure CWF is always up to date.

chore: rename refactoring-agent directory to cs-agent

Update Makefile package targets to reference ~/cs-agent instead of
~/refactoring-agent for darwin arm64 and x64 builds.

chore: fix local builds with local CWF

refactor: reduce complexity in AgentRefactoringService

Extract spawnAgentProcess, setupStderrHandler, setupStdoutHandler from
invokeAgent to reduce cyclomatic complexity. Refactor applyChanges to
use filter/reduce pattern to eliminate nested conditionals. Fix
post-refactoring tests by initializing git repo and mocking extension path.

fix: clean up test-git-repo-integration dir reliably

Add global mocha afterAll hook to clean up test directories after all
tests complete. This catches async operations that recreate directories
after per-suite teardowns run.

test: update agent output fixtures to use enum values

Match the new cs-agent schema that uses fixed enum values for
summary and reasoning instead of freeform strings.

chore: expand CLAUDE.md

feat: use temp directory for agent JSON I/O files

Move render-code-fix input/output JSON files to a temp directory
instead of the repository root to avoid cluttering user projects.
The agent's io_json_dir config option specifies where the reporter
plugin reads and writes these files.

test: verify agent reads input from io_json_dir

Add assertions that prove the agent actually reads from the temp
directory: task_id must match between input and output, and when
fix_proposed, changes must reference the input file.

feat: add settings UI for agent model selection

Add codescene.agentModel dropdown setting with predefined models and
codescene.agentModelOverride text field for custom model identifiers.
The override takes precedence when non-blank.

chore: expand CLAUDE.md

feat: add providerOptions setting for agent configuration

Replace hardcoded opencode_config with user-configurable key-value
pairs in VSCode settings. Keys come from a fixed list (amazon-bedrock:profile,
amazon-bedrock:region) and render as an editable table in the settings UI.

feat: expand Anthropic models

feat: add Test connectivity button in settings

Add a clickable link in the providerOptions setting description that
runs cs-agent's check-connectivity skill to verify provider credentials
are correctly configured.

fix: pass workspace folder as cwd in connectivity test

The connectivity test was failing with "not inside a git repository"
because spawn() wasn't given a cwd, inheriting whatever directory
VS Code was running from.

chore: expand CLAUDE.md

fix: prevent connectivity test from hanging indefinitely

The spawned cs-agent process was blocking because stdin remained open.
Adding stdio: ['ignore', 'pipe', 'pipe'] closes stdin and allows the
process to complete. Also adds timeout (60s default), abort signal
support, and makes the progress notification cancellable.

Integration test requires CS_AGENT_AWS_PROFILE and CS_AGENT_AWS_REGION
environment variables.

feat: add OpenAI, Anthropic, and Google provider auth options

Extend providerOptions to support API key authentication for direct
provider access alongside the existing Amazon Bedrock profile/region
options. The agentModel dropdown now includes models from all four
providers.

Provider options map to cs-agent's expected JSON structure:

  • anthropic:api-key -> anthropic_api_key
  • openai:api-key -> openai_api_key
  • google:api-key -> google_api_key

feat: add tracking config to cs-agent environment

Include tracking.environment: "codescene-vscode" in the agent config
so analytics and MCP events identify this extension as the source.

refactor: separate provider credentials from bedrock config

Split the configuration building logic to distinguish between API key
credentials (Anthropic, OpenAI, Google) and Bedrock-specific options
(profile, region). The buildProviderCredentials function now handles
API keys and populates the top-level provider field in
AgentConfig, while buildOpencodeConfig remains focused solely on
Bedrock configuration within opencode_config.provider.

refactor: simplify conditional in buildProviderCredentials

Extract the complex conditional into a hasAnyApiKey helper function to
reduce cyclomatic complexity and improve readability.

fix: infer agent model from provider credentials

When using OpenAI or Anthropic API keys without an explicit model
selection, the connectivity test was failing because it used the
default Bedrock model. Now getAgentModel() checks providerOptions
and returns a matching model (openai/gpt-4o or anthropic/claude-sonnet-4-0)
when API keys are configured.

fix: infer model from provider keys even with default agentModel

When agentModel had its package.json default value, the model inference
from providerOptions was never reached. Now getAgentModel() checks if
agentModel equals the default before returning it, allowing OpenAI or
Anthropic keys to select the appropriate model automatically.

fix: treat content-identical refactorings as failures

When the agent returns a proposed refactoring but the resulting code is
identical to the original, override the response to unable_to_fix with
low confidence. This prevents no-op refactorings from being presented
as successful suggestions.

vemv added 30 commits September 13, 2026 23:26
Replace the old ACE backend with the local cs-agent binary for
refactoring operations. This eliminates dependency on the ACE
backend service while keeping the existing CWF webview UI.

- Add AgentRefactoringService to invoke cs-agent binary
- Add agent types and configuration modules
- Add VS Code settings for agent model and AWS config
- Add platform-specific package targets in Makefile
- Update .vscodeignore to include bin/ directory
- Add unit tests for mapping logic and config building
- Add integration test for real binary invocation
Aligns with the agentic-ace branch reference implementation:
- Remove agentModel, awsProfile, awsRegion settings
  (agent reads its own config)
- Update user-facing strings from "CodeScene ACE"
  to "CodeScene Agent" or "CodeScene Refactoring Agent"
- Simplify agent config to only pass token and plugins
Clicking "Extension Settings" in the ACE acknowledgement panel was
logging an error because the panel didn't have a handler for the
open-settings message type. Reuse the existing handleOpenSettings
function from cwf-message-handlers.
The agent was being spawned with a temp directory as cwd, causing
"not inside a git repository" errors. Use the git repo root so the
agent can access the entire project and run git commands.
The agent was failing with "UnknownError" because the opencode_config
with Amazon Bedrock provider settings was missing from the agent config.
Also adds the --model argument to explicitly request the Bedrock model.
The agent outputs whole_file_content instead of replacements when
change_type is "whole_file". Also fixes the integration test to
initialize a git repo and adds assertions verifying the agent
writes the expected output file.
Stream progress messages from the refactoring agent binary to the
loading view instead of showing hardcoded rotating messages. The
most recent stdout line is displayed, with newer lines replacing
older ones.
Automatically build and copy CWF from ../cs-webview when running
as vemv, otherwise download from GitHub releases. Make build
depend on updatecwf to ensure CWF is always up to date.
Update Makefile package targets to reference ~/cs-agent instead of
~/refactoring-agent for darwin arm64 and x64 builds.
Extract spawnAgentProcess, setupStderrHandler, setupStdoutHandler from
invokeAgent to reduce cyclomatic complexity. Refactor applyChanges to
use filter/reduce pattern to eliminate nested conditionals. Fix
post-refactoring tests by initializing git repo and mocking extension path.
Add global mocha afterAll hook to clean up test directories after all
tests complete. This catches async operations that recreate directories
after per-suite teardowns run.
Match the new cs-agent schema that uses fixed enum values for
summary and reasoning instead of freeform strings.
Move render-code-fix input/output JSON files to a temp directory
instead of the repository root to avoid cluttering user projects.
The agent's io_json_dir config option specifies where the reporter
plugin reads and writes these files.
Add assertions that prove the agent actually reads from the temp
directory: task_id must match between input and output, and when
fix_proposed, changes must reference the input file.
Add `codescene.agentModel` dropdown setting with predefined models and
`codescene.agentModelOverride` text field for custom model identifiers.
The override takes precedence when non-blank.
Replace hardcoded opencode_config with user-configurable key-value
pairs in VSCode settings. Keys come from a fixed list (amazon-bedrock:profile,
amazon-bedrock:region) and render as an editable table in the settings UI.
Add a clickable link in the providerOptions setting description that
runs cs-agent's check-connectivity skill to verify provider credentials
are correctly configured.
The connectivity test was failing with "not inside a git repository"
because `spawn()` wasn't given a `cwd`, inheriting whatever directory
VS Code was running from.
The spawned cs-agent process was blocking because stdin remained open.
Adding `stdio: ['ignore', 'pipe', 'pipe']` closes stdin and allows the
process to complete. Also adds timeout (60s default), abort signal
support, and makes the progress notification cancellable.

Integration test requires `CS_AGENT_AWS_PROFILE` and `CS_AGENT_AWS_REGION`
environment variables.
Extend `providerOptions` to support API key authentication for direct
provider access alongside the existing Amazon Bedrock profile/region
options. The `agentModel` dropdown now includes models from all four
providers.

Provider options map to cs-agent's expected JSON structure:
- `anthropic:api-key` -> `anthropic_api_key`
- `openai:api-key` -> `openai_api_key`
- `google:api-key` -> `google_api_key`
Include `tracking.environment: "codescene-vscode"` in the agent config
so analytics and MCP events identify this extension as the source.
Split the configuration building logic to distinguish between API key
credentials (Anthropic, OpenAI, Google) and Bedrock-specific options
(profile, region). The `buildProviderCredentials` function now handles
API keys and populates the top-level `provider` field in
`AgentConfig`, while `buildOpencodeConfig` remains focused solely on
Bedrock configuration within `opencode_config.provider`.
Extract the complex conditional into a `hasAnyApiKey` helper function to
reduce cyclomatic complexity and improve readability.
When using OpenAI or Anthropic API keys without an explicit model
selection, the connectivity test was failing because it used the
default Bedrock model. Now getAgentModel() checks providerOptions
and returns a matching model (openai/gpt-4o or anthropic/claude-sonnet-4-0)
when API keys are configured.
When agentModel had its package.json default value, the model inference
from providerOptions was never reached. Now getAgentModel() checks if
agentModel equals the default before returning it, allowing OpenAI or
Anthropic keys to select the appropriate model automatically.
When the agent returns a proposed refactoring but the resulting code is
identical to the original, override the response to `unable_to_fix` with
low confidence. This prevents no-op refactorings from being presented
as successful suggestions.
codescene-access[bot]

This comment was marked as outdated.

@codescene-access codescene-access 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.

Code Coverage Gates Failed
New & Changed Code Coverage: 48.3% (required = 95%)

Review details by gate
  • New & Changed Code Coverage
    • Pass/Fail Reason:
      New or changed code lacks code coverage: 48.3% covered < threshold = 95%

    • Action:
      Add tests to:

      • src/refactoring/agent-service.ts — uncovered line(s) = [16-19,28-34,37-74,77-89,92-110,113-122,125-133,136-164,198-199,268-275]
      • src/refactoring/connectivity.ts — uncovered line(s) = [20-27,32-104]
      • src/extension-impl.ts — uncovered line(s) = [335-336,338-364]
      • src/refactoring/agent-config.ts — uncovered line(s) = [73-79,81-83]
      • src/codescene-tab/webview/ace/cwf-webview-ace-panel.ts — uncovered line(s) = [57,101,235-241]

* chore: add updatecwf target for local CWF development

Automatically build and copy CWF from ../cs-webview when running
as vemv, otherwise download from GitHub releases. Make build
depend on updatecwf to ensure CWF is always up to date.

* chore: fix local builds with local CWF

* fix: make updatecwf work on Windows

Move the local-vs-release CWF logic from a POSIX shell recipe into
scripts/update-cwf.js, since make on Windows runs recipes via cmd.exe.

* fix: run fetch-github-release CLI directly

The package's bin launcher passes a raw Windows path to import(), which
Node rejects. Invoking dist/src/cli.js directly works on all platforms.

---------

Co-authored-by: vemv <vemv@users.noreply.github.com>
codescene-access[bot]

This comment was marked as outdated.

# Conflicts:
#	.gitignore
#	CLAUDE.md
#	Makefile
#	package-lock.json
#	package.json
#	scripts/package-platform.js
#	scripts/update-cwf.js
#	src/code-health-monitor/addon.ts
#	src/codescene-tab/webview-panel.ts
#	src/configuration.ts
#	src/control-center/view-provider.ts
#	src/devtools-api/index.ts
#	src/extension-impl.ts
#	src/simple-executor.ts
#	src/test/setup.ts
#	src/test/suite/git-change-lister.test.ts
codescene-access[bot]

This comment was marked as outdated.

Preflight and fns-to-refactor were ACE-specific. With cs-agent every code
smell is refactorable, so the function to refactor is now resolved locally
from the review (or the whole file for file-level smells).

Test Connectivity no longer requires the "Auth token" setting, and the
Refactor action, CodeLens, status bar item and docs panel are shown only
when Enable Auto Refactor is on and the user is authenticated by any route.

cs-agent hands CS_ACCESS_TOKEN to the CodeScene MCP server and silently
produces no output without it. When no token setting or legacy session
exists, fetch one from `cs-ide auth token --client ide` as an interim until
cs-ide exposes it over JSON-RPC. Missing output now surfaces agent stderr.
codescene-access[bot]

This comment was marked as outdated.

Replace the interim `cs-ide auth token` spawn with the cs-ide/auth-token
request, so the server URL, active account and token refresh are handled by
the running cs-ide instead of a separate process. Pin the CLI build that
ships the request.

The delta presentation tests now expect a single event, since the ACE
enrichment pass that produced the second one is gone.
codescene-access[bot]

This comment was marked as outdated.

…ailing-newline drift

The agent returns search/replace edits written with LF line endings and,
for whole-method edits, a trailing newline. The function body taken from
the editor keeps CRLF on Windows files and ends right after the closing
brace. Neither form matched, so String.replace silently did nothing, the
result equalled the original and a proposed fix was downgraded to
"unable to fix" with an empty diff.

Apply replacements on LF-normalised text, restore the original line
endings afterwards, and retry without trailing newlines when the exact
search is not found. Replacement text is now inserted literally so "$&"
sequences are not interpreted. A search that still does not match logs a
warning with the search and the body.
cs-agent reads the target file from disk, but the refactoring is applied
to the function body taken from the editor buffer. With unsaved edits the
two disagree, the agent's search strings no longer match and the user
ends up on a "Refactoring Failed" panel that only points at the log.

Prompt with a modal before the panel opens: "Save and refactor" saves the
document and continues, dismissing it cancels without opening the panel.
The Retry button goes through the same command. runRefactoring still
rejects a dirty document as a backstop for other callers.
codescene-access[bot]

This comment was marked as outdated.

cs-agent performs refactorings now, so nothing calls the ACE refactor
request. Remove the client method, its cancellation and HTTP-failure
mapping, the response normalizer, log summaries and test fixtures.

Reword the "Auth token" setting, README entry and the missing-sign-in
error so signing in is presented as the normal route for refactoring.

@codescene-access codescene-access 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.

Gates Passed
4 Quality Gates Passed

See analysis details in CodeScene

Quality Gate Profile: Clean Code Collective
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.

This branch has not been deployed

No deployments
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