Repository navigation
Replace writeConfigObject with AI-aware updateConfigObject - #1537
Conversation
Apply RDE config updates in place instead of overwriting the whole file. Plain static configs keep the deterministic render (fast path, no AI). Configs with custom structure (imports, helper wrappers, external text refs) are edited by a headless Claude agent so user-authored structure is preserved and externally-referenced files are updated rather than inlined. Every edit is validated (semantic when the config is evaluable, structural fallback otherwise) and hard-fails on mismatch. Co-Authored-By: mantra <[email protected]>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a deterministic in-place config update API that fast-paths static literal configs and uses a headless Claude agent for complex edits; includes parsing helpers, agent runner, validation + rollback, tests with agent mocking, and manager integration. ChangesRemote Development Environment config update system
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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
🧹 Nitpick comments (3)
packages/stack-shared/src/stack-config-file.ts (1)
118-139: ⚡ Quick winParser plugin inconsistency:
importAttributesnot enabled inparseStackConfigFileContent.
stackConfigFileExportsConfigusesplugins: ["typescript", "importAttributes"](line 123) to parse files with import attributes syntax (e.g.,import x from "./file.txt" with { type: "text" }), but the existingparseStackConfigFileContent(line 145) only includes["typescript"].This means a file with import attributes will:
- Pass the structural check in
stackConfigFileExportsConfig- Fail to parse in
parseStackConfigFileContent/tryParseStackConfigFileContentWhile this triggers the intended AI path (since
tryParseStackConfigFileContentreturnsnull), it creates an asymmetry where the validation helper accepts syntax the evaluation helper rejects. Consider adding"importAttributes"toparseStackConfigFileContent's plugin list for consistency, even if those files ultimately can't be statically evaluated.Proposed fix
export function parseStackConfigFileContent(content: string, filePath: string): ParsedStackConfig { if (content.trim() === "") return {}; const ast = parser.parse(content, { sourceType: "module", - plugins: ["typescript"], + plugins: ["typescript", "importAttributes"], });🤖 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 `@packages/stack-shared/src/stack-config-file.ts` around lines 118 - 139, The parser plugin list is inconsistent: stackConfigFileExportsConfig parses with plugins ["typescript","importAttributes"] but parseStackConfigFileContent only uses ["typescript"], causing files with import attributes to be accepted by the export-check but fail actual parsing; update parseStackConfigFileContent (and any helper tryParseStackConfigFileContent) to include "importAttributes" in its parser plugins so both checks use the same plugin set (referencing the parseStackConfigFileContent and tryParseStackConfigFileContent functions to locate the change).apps/dashboard/src/lib/remote-development-environment/config-update-agent.ts (1)
37-62: Consider adding a timeout to prevent indefinite agent execution.The agent stream has no timeout constraint, so a stuck or slow agent could block config updates indefinitely. While the tools are safely restricted and this runs in a local dev environment, users waiting for config updates would experience poor UX.
Consider wrapping the agent call with a timeout (e.g., using
Promise.racewith a timeout promise) and providing clear error messaging when the timeout is exceeded.🤖 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/dashboard/src/lib/remote-development-environment/config-update-agent.ts` around lines 37 - 62, Add a bounded timeout around the streaming call to query inside runConfigUpdateAgent so the agent cannot run indefinitely: wrap the for-await loop (the call to query({...}) that yields message objects) in a Promise.race with a timeout promise (e.g., setTimeout that rejects after a configurable duration) and ensure the timeout path cleanly aborts/cleanup and throws a clear error (e.g., "Config update agent timed out after X ms") so callers know the agent was terminated; keep the existing error handling for message.type === "result" and non-success subtypes and ensure any resources or streams from query are closed/aborted on timeout.apps/dashboard/src/lib/remote-development-environment/config-file.ts (1)
131-148: 💤 Low valueFast path commits changes before validation.
Lines 142-144:
renderConfigObjectToFileatomically writes the file, then validation reads it back. If validation fails (line 145), the file has already been replaced with the potentially incorrect config. Since this is the deterministic path, a validation failure would indicate a bug in the rendering logic rather than corrupted input.However, for consistency with fail-safe patterns, consider validating the rendered content in memory before writing to disk.
🤖 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/dashboard/src/lib/remote-development-environment/config-file.ts` around lines 131 - 148, The current fast path calls renderConfigObjectToFile(configFilePath, target) before validating the written file, which can replace the on-disk file with a bad render; instead render the config to a string in memory, validate that string against the expected canonicalized target (using canonicalizeConfig, isValidConfig, configsEqual, etc.), and only if validation passes call renderConfigObjectToFile (or an existing atomic writer) to persist it; if you need a helper, add renderConfigObjectToString(target) or change renderConfigObjectToFile to optionally accept pre-rendered content, validate the in-memory render against target and throw before writing to disk, using the same configFilePath, configUpdate, tryParseStackConfigFileContent flow for locating target.
🤖 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/dashboard/src/lib/remote-development-environment/config-file.ts`:
- Around line 150-160: Before calling runConfigUpdateAgent, snapshot the current
state (read and store contents) of configFilePath and any
imported/externally-referenced files (use tryReadConfigForValidation as a hook
to gather baselineConfig and extend it to collect referenced files); run the
agent in a temp working directory or apply changes to temporary files, then call
validateAgentUpdate; if validateAgentUpdate throws, restore the original files
from the snapshot and rethrow the error, otherwise atomically replace the
originals with the validated updates—ensure the save/restore logic is tied to
configFilePath, baselineConfig, runConfigUpdateAgent, and validateAgentUpdate so
failures never leave configs mutated without a rollback.
- Around line 207-221: The flattenConfigUpdate function (walk inner function)
currently recurses into plain objects but drops empty objects because
Object.entries yields no entries; update walk so that when value is a plain
object and has zero keys you treat it as a leaf and push a ConfigChange ({ path:
fullPath, value: {} }) instead of recursing, while preserving existing recursion
for non-empty plain objects; refer to functions/types flattenConfigUpdate, walk,
Config and ConfigChange to locate the logic to change.
In
`@apps/dashboard/src/lib/remote-development-environment/config-update-agent.ts`:
- Around line 22-29: The function stripClaudeCodeEnv currently asserts
process.env as Record<string,string>, which is unsafe because process.env values
can be undefined; update stripClaudeCodeEnv to produce a true
Record<string,string> by iterating over Object.entries(process.env) (or
Object.keys) and copying only keys with non-undefined string values into a new
object, ensure CLAUDECODE is omitted (delete or skip it during the copy), and
return that validated object instead of using a type cast; refer to the
stripClaudeCodeEnv function name to locate and replace the unsafe assertion.
---
Nitpick comments:
In `@apps/dashboard/src/lib/remote-development-environment/config-file.ts`:
- Around line 131-148: The current fast path calls
renderConfigObjectToFile(configFilePath, target) before validating the written
file, which can replace the on-disk file with a bad render; instead render the
config to a string in memory, validate that string against the expected
canonicalized target (using canonicalizeConfig, isValidConfig, configsEqual,
etc.), and only if validation passes call renderConfigObjectToFile (or an
existing atomic writer) to persist it; if you need a helper, add
renderConfigObjectToString(target) or change renderConfigObjectToFile to
optionally accept pre-rendered content, validate the in-memory render against
target and throw before writing to disk, using the same configFilePath,
configUpdate, tryParseStackConfigFileContent flow for locating target.
In
`@apps/dashboard/src/lib/remote-development-environment/config-update-agent.ts`:
- Around line 37-62: Add a bounded timeout around the streaming call to query
inside runConfigUpdateAgent so the agent cannot run indefinitely: wrap the
for-await loop (the call to query({...}) that yields message objects) in a
Promise.race with a timeout promise (e.g., setTimeout that rejects after a
configurable duration) and ensure the timeout path cleanly aborts/cleanup and
throws a clear error (e.g., "Config update agent timed out after X ms") so
callers know the agent was terminated; keep the existing error handling for
message.type === "result" and non-success subtypes and ensure any resources or
streams from query are closed/aborted on timeout.
In `@packages/stack-shared/src/stack-config-file.ts`:
- Around line 118-139: The parser plugin list is inconsistent:
stackConfigFileExportsConfig parses with plugins
["typescript","importAttributes"] but parseStackConfigFileContent only uses
["typescript"], causing files with import attributes to be accepted by the
export-check but fail actual parsing; update parseStackConfigFileContent (and
any helper tryParseStackConfigFileContent) to include "importAttributes" in its
parser plugins so both checks use the same plugin set (referencing the
parseStackConfigFileContent and tryParseStackConfigFileContent functions to
locate the change).
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 06275c5a-cde6-453a-946f-32a282dde88a
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (7)
apps/dashboard/package.jsonapps/dashboard/src/lib/remote-development-environment/config-file.test.tsapps/dashboard/src/lib/remote-development-environment/config-file.tsapps/dashboard/src/lib/remote-development-environment/config-update-agent.tsapps/dashboard/src/lib/remote-development-environment/manager.tspackages/stack-shared/src/config-rendering.tspackages/stack-shared/src/stack-config-file.ts
There was a problem hiding this comment.
Pull request overview
This PR replaces the dashboard RDE config update mechanism from a lossy, full-file overwrite (writeConfigObject) to an async, in-place update flow (updateConfigObject) that preserves user-authored config structure (imports, wrappers, external file references). It introduces a fast deterministic path for plain static literal configs and an AI-agent-driven path for structured configs, with post-edit validation to hard-fail on mismatches.
Changes:
- Add shared helpers to detect “static literal” configs and perform a lightweight structural sanity check (
tryParseStackConfigFileContent,stackConfigFileExportsConfig). - Implement
updateConfigObjectwith deterministic fast-path rendering vs. AI agent editing + validation. - Extend RDE watcher suppression to cover the full async update window; add tests with a mocked agent runner.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/stack-shared/src/stack-config-file.ts | Adds parsing helpers and a structural export check for post-edit validation. |
| packages/stack-shared/src/config-rendering.ts | Re-exports new shared helpers and adds tests for them. |
| apps/dashboard/src/lib/remote-development-environment/manager.ts | Holds watcher-suppression across async updates and adjusts sync scheduling. |
| apps/dashboard/src/lib/remote-development-environment/config-update-agent.ts | Adds a headless Claude agent runner for in-place config edits. |
| apps/dashboard/src/lib/remote-development-environment/config-file.ts | Replaces overwrite logic with updateConfigObject including validation + prompting. |
| apps/dashboard/src/lib/remote-development-environment/config-file.test.ts | Adds tests covering fast path, external-file updates, and validation failure cases. |
| apps/dashboard/package.json | Adds @anthropic-ai/claude-agent-sdk dependency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
5 issues found across 8 files
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.
Re-trigger cubic
Co-Authored-By: mantra <[email protected]>
|
@greptile-ai review |
dev moved pnpm.overrides from package.json into pnpm-workspace.yaml (commit 82f470e), which pnpm 11.5.0 reads. Regenerated the lockfile so its overrides block matches, fixing ERR_PNPM_LOCKFILE_CONFIG_MISMATCH on frozen install. Co-Authored-By: mantra <[email protected]>
|
Regarding the 4/5 finding on This is a false positive — the removal was intentional because onClick={(e) => runAsynchronouslyWithAlert(handleClick(e))}Both @greptile-ai review |
…int rule Co-Authored-By: mantra <[email protected]>
…adeoff Co-Authored-By: mantra <[email protected]>
|
Fixed both observations in 2e40e48:
@greptile-ai review |
… examples/demo/hexclave.config.ts
|
@greptile-ai review |
…edundant jiti evaluation Co-Authored-By: mantra <[email protected]>
|
Addressing the two findings from the latest review: Issue 1 —
// apps/dashboard/src/components/ui/button.tsx:80
onClick={(e) => runAsynchronouslyWithAlert(handleClick(e))}The previous explicit Issue 2 — Fixed in bc68197: moved @greptile-ai review |
|
Addressed the two remaining observations from the 5/5 review: Observation 1 — Structural no-op should not hard-fail Changed the no-op check in Observation 2 — Removed All 13 tests pass (4 local-config-updater + 9 dashboard config-file). @greptile-ai review |
…ad of throwing, remove dead MultiEdit/NotebookEdit from FILE_MUTATING_TOOLS Co-Authored-By: mantra <[email protected]>
The TypeScript config type does not accept null for individual sign-up rule entries. Replaced with properly-typed disabled rules that demonstrate the feature without breaking the build. Co-Authored-By: mantra <[email protected]>
|
Fixed the |
Co-Authored-By: mantra <[email protected]>
|
Fixed lint (4→2 space indentation in manager.ts imports) and demo config type error (null→typed rule objects). @greptile-ai review |
Co-Authored-By: mantra <[email protected]>
|
Merged dev + regenerated docs codegen (setup.mdx, llms-full.txt, hexclave-agent-reminders.jsx, home-prompt-island.jsx). @greptile-ai review |
N2D4
left a comment
There was a problem hiding this comment.
why is there a fast path and an agent path? i generally don't like fallbacks, so i think we should avoid doing that. i think we can always use the agent path.
generally also the PR turned out larger than i expected. what do you think the reason is? is there a way to simplify it you think? trying to update my priors here
do we need an extra package for the local-config-updater? can we have it in stack-shared instead?
there is no fallback here
and the reason for local-config-updater and not stack shared is cuz claude code was getting bundled with the sdks |
There was a problem hiding this comment.
does this need to be its own package? can't we have it in stack-shared? feels superfluous to add an extra package just for this
- Removed all instances of '@hexclave/local-config-updater' and replaced them with '@hexclave/shared-backend' across various files, including configuration and test files. - Introduced a new package '@hexclave/shared-backend' with its own configuration and dependencies. - Updated pnpm-lock.yaml to reflect the new package structure and dependencies. - Ensured that all related imports and usages are correctly pointing to the new shared-backend package. This change centralizes the configuration management under the shared-backend package, improving maintainability and clarity in the codebase.
- Updated various dependencies in pnpm-lock.yaml, including downgrading '@supabase/supabase-js' and related packages from version 2.107.0 to 2.106.2. - Adjusted eslint-related dependencies to use [email protected] instead of [email protected]. - Added new environment variables 'CRON_SECRET_OLD' and 'BLOB_READ_WRITE_TOKEN' in turbo.json for enhanced configuration management.
Summary
Replaces
writeConfigObject(destructive overwrite) withupdateConfigObject— an async, AI-aware updater that preserves user-authored config structure (imports, external file references, helpers).Dual-path approach:
override()+ in-memory validation + atomic writeimport x from "./file.txt" with { type: "text" }etc. → Claude agent edits the external files in place, then validatesSafety guarantees:
../escapes)settingSources: [],strictMcpConfig: true,CLAUDE_CODE_DISABLE_AUTO_MEMORY, no Bash toolscheduleSynconly fires after a successful updateCI failures are preexisting on
dev(ERR_PNPM_LOCKFILE_CONFIG_MISMATCHfrom overrides move without lockfile regen); this branch has zero lockfile changes vs dev.Link to Devin session: https://app.devin.ai/sessions/cc7409a357bc472ea19fbed065f1229f
Requested by: @mantrakp04
Summary by CodeRabbit
New Features
Chores
Documentation
Docs for this feature were added in this branch:
docs-mintlify/guides/going-further/local-development.mdx— coversstack dev, the development-environment flow, and how dashboard edits are written back to the local config file (structure-preserving fast path vs. assistant path, externalimport … with { type: "text" }templates, validation + rollback). Added todocs.jsonnav; also fixes the previously-broken/guides/going-further/local-developmentlinks fromindex.mdxandself-host.mdx.docs-mintlify/guides/going-further/cli.mdx— added astack dev("Run a development environment") section.config-docsanddashboard-instructionsplaceholders underpackages/stack-shared/src/ai/unified-prompts/skill-site-prompt-parts/, and added a structure-preserving note to the setup prompt.CHANGELOG.md— user-facing entry.