Skip to content

fix(studio-server): history writes and claims follow Studio's write rule - #7988

Merged
michaelwang11394 merged 1 commit into
mainfrom
sec-history-writes-tool-configs-1116
Nov 17, 2026
Merged

michaelwang11394 merged 1 commit into
mainfrom
sec-history-writes-tool-configs-1116

Conversation

@michaelwang11394

@michaelwang11394 michaelwang11394 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What

  • History undo, restore and Cmd+Z leave alone every file that Studio's file routes refuse to write. The rest of the entry is still put back.
  • Cmd+Z passes over a pending or recorded change that touched only such files.
  • A claim no longer takes such a file's pending change.
  • A claim's overwrote version counts only when the server itself saw that version at that path.
  • Studio's write rule now also refuses the scripts the project's package.json runs.
  • The shared tool-trusted name rule refuses more files that tools and agents load on their own.

Why

A composition's script in an ordinary preview runs on the same origin as the Studio API. #7964 stopped the file routes from writing package.json, agent instructions and scripts, but the history routes had a second way in:

  1. The script writes chosen bytes to an ordinary file, so history keeps a copy under a hash the script knows.
  2. Something outside Studio changes package.json, for example the developer's editor, agent or package manager. The change stays pending for a moment.
  3. The script claims that pending change and names its own hash in overwrote. History had heard no overwrite of its own, so it took the client's word and made that hash the entry's earlier state.
  4. The script undoes the entry. Undo wrote the chosen bytes into package.json, because history writes ran only containment checks.

Undo, restore and step could also roll back or delete such files with no setup at all.

Separately, the name rule was a fixed list. It missed agent settings such as opencode.json, override files such as docker-compose.override.yml and lefthook-local.yml, and the files nodemon, mise and other tools load. It also missed a project-root script such as build.mjs that package.json runs.

How

packages/studio-server/src/history/projectHistory.ts

  • studioWouldWrite(path) applies Studio's write rule (isWritableInProject) to a project-relative path.
  • writeAs, which backs undo, restore and step, drops target paths the rule refuses. Those files keep their current bytes.
  • next() skips a pending group or entry with no file the rule allows. So Cmd+Z never gets stuck on a change it cannot undo.
  • takeClaimed ignores refused paths.
  • SeenVersions keeps, per path, the latest 32 hashes the server found there (every tracked hash) or that a Studio write replaced there. A claim's overwrote hash is used only if it is in that set. Otherwise the claim takes the whole pending change, and its earlier state is what history really saw. A legitimate cut is always a version the server saw at that path, because a cut also needs the stored copy that only a sweep or a heard write makes. So no real claim loses anything.
  • Links are left to history's existing checks, which still refuse an undo through a link with "is in the way".

packages/studio-server/src/helpers/safePath.ts

  • isWritableInProject(projectDir, relPath) is isWritableProjectPath plus one more refusal: a JS or TS file that the project's package.json names in main, bin or scripts (node ./build.mjs, tsx scripts/gen.ts --out=dist). The parsed list is cached until package.json changes. isWritableProjectFile, which the file routes use, now goes through it.
  • I did not refuse every root-level script. Real projects keep script.js beside index.html, and Studio has to keep editing it.

packages/core/src/safePath.ts adds these names to toolTrustedFileKind:

Added Why
opencode.json, opencode.jsonc, crush.json Agent settings read from the project folder. They can start MCP and LSP servers. Other agents' settings live in hidden folders, which the write rule already refuses.
docker-compose.override.*, compose.override.* docker compose loads them next to the main file.
Dockerfile.*, *.dockerfile, Containerfile Alternate Dockerfile spellings that compose files and builds name.
lefthook-local.*, lefthook.{yml,yaml,json,jsonc,toml} Every spelling lefthook loads. Its hooks run on each commit.
Taskfile.dist.yml / .yaml Task loads it when Taskfile.yml is missing.
mise.toml, mise.*.toml, mise/config.toml mise runs their tasks and hooks when the developer enters the folder.
nodemon.json, devbox.json, devenv.yaml They name commands that run on start or on shell entry.
wrangler.{toml,json,jsonc}, vercel.json, netlify.toml Their dev and deploy CLIs run the build command these files name.
composer.json Composer runs its scripts.
Gemfile, Rakefile, Vagrantfile, Tiltfile, Earthfile, Brewfile Build files that are code in their own language.
*.config.jsonc, tsconfig.*.json, jsconfig.*.json Other spellings of configs the rule already protected. tsconfig.json extends the named variants.
simple-git-hooks.{json,js,cjs,mjs} Its hooks run on each commit.
.nix, .fish Scripts that nix-shell or the fish shell run.

Hidden names such as .envrc, .mise.toml, .mcp.json and .vscode/ were already refused by the hidden-path rule.

The CLI history docs now say what undo and restore leave alone.

Test plan

  • New routes/history.protected.test.ts, which drives the HTTP routes:
    • Undo and restore put index.html back and leave AGENTS.md, a package.json script and a new opencode.json byte-identical.
    • Cmd+Z returns no step and leaves package.json alone when an outside edit changed only that file.
    • A claim that names bytes stored for other.html as index.html's overwritten version cannot make undo write them.
    • A claim on an outside change to package.json takes nothing.
    • All four fail on main and pass here.
  • helpers/safePath.test.ts: package.json scripts are refused in any spelling the rule folds. Composition scripts, folders and unnamed files stay writable. A changed package.json is re-read, and a missing or broken one changes nothing.
  • core/src/safePath.test.ts: every new name and spelling, plus look-alikes such as compositions/docker.html, assets/mise-en-scene.png and assets/script.js that must stay writable.
  • Ran vitest run on studio-server helpers/safePath, routes/history*, history/* and routes/files* (687 passed, 3 skipped), on core safePath (177 passed) and on the CLI registry/installer (69 passed). Also ran tsc --noEmit for core and studio-server, scripts/lint-registry-items.mjs (448 items, 0 errors) and the comment ratchet.

History undo, restore and Cmd+Z now leave alone every file that Studio's
file routes refuse to write. This covers tool-trusted, private, hidden and
node_modules paths, and scripts the project's package.json runs. Cmd+Z
passes over an edit that only changed such files. A claim no longer takes
such a file's pending change.

A claim's `overwrote` version now counts only when the server itself saw
that version at that path. A version stored for another file can no longer
become a file's earlier state.

The write rule also refuses more files that tools and agents load on
their own: opencode and crush settings, compose override files,
Dockerfile.* and Containerfile, every lefthook spelling, mise, nodemon,
devbox, wrangler, vercel and netlify settings, *.config.jsonc,
tsconfig.*.json, Taskfile.dist, simple-git-hooks, Ruby build files, and
.nix and .fish scripts.
@mintlify

mintlify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
hyperframes 🟢 Ready View Preview Nov 17, 2026, 12:16 AM

💡 Tip: Enable Automations to automatically generate PRs for you.

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 93 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (8)

Unstable (2)

  • seqrotatenudge-none-pct-r0-root-z100: tracking 0.03, pressJump 0, drop 0, reload 3.03, render 0.04, renderKey -, undo false, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.08, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.08, renderKey -, undo true, teleport true
  • seqplainkeys-none-px-r0-root-z100: tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo false, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true

@eddy-heygen eddy-heygen 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.

(Eddy's agent) Reviewed by Eddy's Claude agent at commit 5aa35a7.

Verdict: approved, good to ship.

Summary. Studio's history routes (undo, restore, the undo-shortcut step and claims) wrote files with containment checks only, so they were looser than the file routes: they could roll back, delete or replace files the file routes refuse to write. This PR makes the single write sink behind undo, restore and step, the claim path, and the next-step lookup apply the same rule the file routes use. A claim's "overwrote" version is accepted only if the server itself recorded that version at that path. The shared tool-trusted name list is widened, and Studio also refuses script files that the project's root package manifest names. The rule is checked at the time of use, so history entries already on disk are covered. 7 files; a reviewer agent read the full diff and I read its findings against the changed files.

Blockers

None.

Non-blockers

  • packages/studio-server/src/history/projectHistory.ts: the undo conflict check still counts files that undo will no longer write, so an undo can report a conflict on a file it would have skipped anyway.
  • packages/core/src/safePath.ts: on Windows, the short (8.3) forms of the newly added file-name spellings are not recognised by the name list.
  • packages/studio-server/src/helpers/safePath.ts: the detection of script files named by the package manifest reads only the root manifest's main, bin and scripts entries. It misses other ways a manifest can name code, and it can also refuse an ordinary composition file that happens to be named there. Worth tightening in a follow-up; neither case is worse than before this PR.
  • Tests: the four new route tests cover the main cases; a test for an entry that was already on disk before the change would pin the time-of-use behaviour.

CI: all checks pass at this commit, including the Windows test jobs; none failing or pending.

How this was reviewed: a code-review pass and a security-review pass by a reviewer agent in an isolated checkout of this commit; I then read its findings against the diff. Nothing was built or run.

@michaelwang11394
michaelwang11394 added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit 32fe10a Nov 17, 2026
143 of 144 checks passed
@michaelwang11394
michaelwang11394 deleted the sec-history-writes-tool-configs-1116 branch November 17, 2026 01:08
This was referenced Nov 17, 2026

This branch was successfully deployed

1 active deployment
staging - docs — 5aa35a7c Deployed Nov 17, 2026 by mintlify[bot]
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.

2 participants