Skip to content

feat(ui): editable file panel with CodeMirror and sessions.files.set hash-CAS writes - #104757

Merged
steipete merged 9 commits into
mainfrom
claude/file-preview-edit-syntax-2cce6d
Jul 12, 2026
Merged

steipete merged 9 commits into
mainfrom
claude/file-preview-edit-syntax-2cce6d

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #104698

What Problem This Solves

The Control UI file detail panel (from #100615) is read-only, and file paths in tool cards are dead text. Operators reviewing an agent's work cannot make a small correction to a file the agent just touched — a doc typo, a config value — without leaving the browser, which is impossible when the workspace lives on a remote gateway host ("Open in editor" cannot reach it).

Why This Change Was Made

  • Gateway: new sessions.files.set RPC (operator.admin) that overwrites one existing workspace file with compare-and-swap semantics on a sha256 content hash. sessions.files.get now returns that hash for strict-UTF-8 text files (the hash doubles as the editability signal — binary previews never get one, and set independently rejects non-text targets so replacement-character re-encoding can never corrupt a binary file). Writes go through the same fs-safe root as reads (realpathed root, symlink/hardlink rejection, path containment, 256 KB UTF-8 cap); no create/delete. The workspace-browser module explicitly deferred general writes to a "separately reviewed mutation contract" — this PR is that contract, following the agents.files.set admin-scope precedent. Protocol change is additive (no version bump).
  • UI: the file panel now renders through CodeMirror 6 for both viewing and editing, replacing the hand-rolled highlight.js line renderer (one canonical path; the old HTML-splitting helpers are deleted). Existing affordances are preserved: line numbers, jump-to-line, in-file search, copy, Show in Files, open-in-external-editor. Edit mode (pencil, gated on sessions.files.set advertisement + operator.admin) adds dirty tracking, Cmd/Ctrl-S save, and a conflict banner with Reload / Overwrite when the file changed on disk since load. CodeMirror ships as a lazy Vite chunk (file-editor-view 46 kB + per-language chunks), loaded on first panel open.
  • Tool cards: file paths in expanded read/edit/write cards are now clickable and open the same panel (collapsed rows are untouched — they are already one big toggle button).
  • One real bug found during live verification and fixed here: the app shell is slotted through the tooltip provider's shadow root, so CodeMirror's default root detection mounted its base theme into that shadow root where slotted light-DOM content can't see it. The editor now pins root: document (see the inline comment in file-editor-view.ts).

User Impact

Operators with admin scope can view and edit workspace text files directly from chat context on any gateway, with agent-write conflict safety. Read-only operators and older gateways see the unchanged read-only viewer (the edit affordance is capability-gated). File references in tool cards become navigable like chat prose links already were.

Evidence

Screenshots (mock gateway harness, agent:alpha fixture):

Viewer Edit mode (dirty) Saved
viewer dirty saved

Validation:

  • Gateway: sessions-files + agents-workspace suites green locally (both shards) and 40/40 on Blacksmith Testbox (Linux) for the initial RPC coverage. Cases: CAS happy path, stale-hash conflict with currentHash, missing file, >256 KB rejection, ../ escape + symlink containment (no write outside root), binary preview without a hash, binary write rejection even with a matching byte hash, UTF-8 BOM byte round-trip, and set skipping the transcript scan.
  • UI: jsdom suites (chat-sidebar, chat-tool-cards) green; new Chromium browser suite (chat-sidebar-file-view.browser.test.ts) 7/7 covering render/target-line decoration, edit→dirty→save, CRLF round-trip through save, in-flight-save dirty tracking, conflict→Reload, edit-mode drop when a reload returns non-editable content, and read-only-while-reloading (skips cleanly in the jsdom shard, which also collects *.browser.test.ts).
  • e2e: chat-file-links.e2e.test.ts green with no selector changes (the CodeMirror line decorations keep the file-view__line--target/data-line contract).
  • Build: vite build green; CodeMirror in a separate lazy chunk (file-editor-view-*.js 46.25 kB gzip 13.25 kB; language definitions split per language).
  • Live: full flow verified in the mock dev harness (open from workspace rail → CodeMirror view → edit → save), which now models sessions.files.get hashes and sessions.files.set.
  • Autoreview (Codex, structured, iterated until clean): eight findings triaged — missing-lockfile was a bundle artifact (the real branch commits the lockfile; it was excluded from the review bundle because integrity hashes trip the secret scanner); the CAS-window finding is an accepted system bound (agents write from their own OS processes; documented inline); six were real and are fixed here with regression tests: binary/non-UTF-8 files could be "edited" and corrupted (no CAS hash for non-text now, set rejects non-text targets), UTF-8 BOMs were silently dropped on save (ignoreBOM decode), CRLF/CR files were normalized to LF on save (EditorState.lineSeparator + sliceDoc serialization), mixed-line-ending files now stay read-only (hasUniformLineEndings gate), a conflict Reload re-checks that gate and drops edit mode when the latest content no longer qualifies, and set rejects NUL-containing replacement content so the API never writes a file its own editability checks classify as binary.
  • Known proof gaps: the local npm shrinkwrap guard lane fails in this environment on npm 12/Node 26 — it fails identically against main's untouched lockfile, so it is environmental; hosted CI (Linux Node 24) is authoritative. Two Blacksmith Testbox leases died mid-check:changed (infra outage); all other local lanes were green.

@steipete
steipete requested a review from a team as a code owner July 11, 2026 22:48
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime scripts Repository scripts labels Jul 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Guard

This PR changes dependency-related files. Maintainers should confirm these changes are intentional.

Changed files:

  • pnpm-lock.yaml
  • ui/package.json

Maintainer follow-up:

  • Review whether the dependency changes are intentional.
  • Inspect resolved package deltas when lockfile, shrinkwrap, or workspace dependency policy changes are present.
  • Treat package-lock.json and npm-shrinkwrap.json diffs as security-review surfaces.
  • Run pnpm deps:changes:report -- --base-ref origin/main --markdown /tmp/dependency-changes.md --json /tmp/dependency-changes.json locally for detailed release-style evidence.

@github-actions github-actions Bot added the dependencies-changed PR changes dependency-related files label Jul 11, 2026
@github-actions

github-actions Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Dependency graph changes noted

This PR includes dependency graph changes. The dependency guard is informational because the PR author is a repository admin or a member of @openclaw/openclaw-secops.

  • Current SHA: 262b6437d52cef04b0d16755a21ab8316d122bbb
  • Trusted actor: @steipete
  • Trusted role: pull request author; openclaw-secops

Security review is still recommended before merge when the dependency graph change is intentional.

@openclaw-barnacle openclaw-barnacle Bot added size: XL maintainer Maintainer-authored PR labels Jul 11, 2026
@steipete
steipete force-pushed the claude/file-preview-edit-syntax-2cce6d branch from 8260a5c to dfbc9f5 Compare July 11, 2026 22:51

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8260a5c610

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +419 to +423
const canEdit =
typeof file.hash === "string" &&
hasUniformLineEndings(file.content) &&
isGatewayMethodAdvertised(state, "sessions.files.set") !== false &&
hasOperatorAdminAccess(state.hello?.auth ?? null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Route Markdown files through the editable file view

Because this edit gate is below the .md/.markdown/.mdx early return above, opening a Markdown file without a line target (for example from the workspace rail or Show in Files) still returns kind: "markdown" instead of a kind: "file" sidebar with the edit payload. Even when the Gateway returns a hash and advertises sessions.files.set to an admin, the Edit button never appears for those common doc files, so the new in-browser edit flow misses the doc-typo use case unless the user happens to open a line-specific link.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jul 11, 2026
@clawsweeper

clawsweeper Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 11, 2026, 8:33 PM ET / July 12, 2026, 00:33 UTC.

Summary
The PR adds an admin-scoped sessions.files.set hash-CAS overwrite RPC, replaces the Control UI file viewer with a lazy CodeMirror viewer/editor, and makes expanded tool-card file paths open that panel.

PR surface: Source +997, Tests +430, Docs +1, Config +6, Other +589. Total +2023 across 28 files.

Reproducibility: yes. for the review findings: exact current-head source inspection deterministically shows the Markdown early return and the nullable capability check enabling edits.

Review metrics: 2 noteworthy metrics.

  • Gateway API surface: 1 write RPC added, 1 read result extended. The PR creates a public admin mutation method and a CAS editability token.
  • Direct UI dependencies: 6 added. CodeMirror and Lezer expand the shipped browser dependency graph, although the pinned provenance is consistent.

Stored data model
Persistent data-model change detected: serialized state: packages/gateway-protocol/src/schema/sessions.ts, serialized state: src/gateway/server-methods/sessions-files.test.ts, serialized state: src/gateway/server-methods/sessions-files.ts, serialized state: ui/src/lib/sessions/index.ts, unknown-data-model-change: src/gateway/server-methods/sessions-files.test.ts, unknown-data-model-change: src/gateway/server-methods/sessions-files.ts, and 2 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #104698
Summary: This PR implements the canonical feature issue and partially overlaps another open, proof-positive implementation.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦐 gold shrimp
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Fix both current-head findings with focused regression coverage.
  • Post redacted real-Gateway proof covering edit, save, stale conflict, reload, and overwrite.
  • Obtain explicit maintainer acceptance of the canonical API and its race semantics.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The PR shows mock-Gateway screenshots and automated coverage, but not after-fix edit, save, and stale-conflict behavior against a real Gateway workspace. Add a redacted real-Gateway recording or live diagnostic transcript; after updating the PR body, review should rerun automatically, or a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] The documented external-process check-then-write window can overwrite a file change made after hash validation; this is an intentional but security-sensitive contract choice.
  • [P1] Two live pull requests propose overlapping public workspace-editing APIs and UI behavior, so merging without choosing one canonical direction would create maintenance and compatibility drift.
  • [P1] The contributor evidence exercises the mock Gateway harness rather than a real Gateway workspace, leaving the actual remote save and stale-conflict path unproven.

Maintainer options:

  1. Fix and prove the selected contract (recommended)
    Require positive method advertisement, route Markdown through the editable view, and add redacted real-Gateway save and conflict proof before merge.
  2. Pause for API consolidation
    Hold this branch while maintainers select one durable workspace-editing protocol and UI implementation.
  3. Accept the race semantics
    Proceed only after maintainers explicitly accept the documented external-process overwrite window.

Next step before merge

  • [P1] Two mechanical repairs are clear, but the permanent API and race decision plus contributor-specific real-Gateway proof require maintainer handling.

Maintainer decision needed

  • Question: Should this bounded hash-CAS sessions.files.set contract become OpenClaw's canonical workspace editor, rather than or combined with Preview session workspace images and unsupported files #95956?
  • Rationale: The choice defines a new public remote mutation boundary, including accepted external-writer race semantics, while two viable open branches currently implement overlapping contracts.
  • Likely owner: steipete — They introduced the current file-viewer surface and authored the canonical feature issue and this exact contract proposal.
  • Options:
    • Adopt and repair this PR (recommended): Keep the existing-file hash-CAS design, fix capability and Markdown behavior, and require real-Gateway proof.
    • Adopt the older PR: Choose Preview session workspace images and unsupported files #95956 if its broader preview and editing contract is preferred.
    • Consolidate into one replacement: Select the permanent protocol first and combine only the strongest proven pieces from both branches.

Security
Needs attention: Package provenance is consistent and containment guards are strong, but the remote mutation contract's accepted race window still needs explicit maintainer ownership.

Review findings

  • [P1] Require positive method advertisement before enabling edits — ui/src/pages/chat/components/chat-session-workspace.ts:422
  • [P2] Route Markdown through the editable file view — ui/src/pages/chat/components/chat-session-workspace.ts:412-417
Review details

Best possible solution:

Adopt one canonical, positively advertised operator.admin existing-file write contract; route all editable strict-text files, including Markdown, through one editor path with rendered Markdown available as a view mode; retain the size, encoding, containment, no-create, and conflict safeguards; and require redacted real-Gateway edit/save/conflict proof before merge.

Do we have a high-confidence way to reproduce the issue?

Yes for the review findings: exact current-head source inspection deterministically shows the Markdown early return and the nullable capability check enabling edits.

Is this the best way to solve the issue?

No, not yet: hash-CAS existing-file writes are a reasonable bounded design, but this branch is not fail-closed on capability discovery, misses common Markdown edits, and has not been selected over the competing contract.

Full review comments:

  • [P1] Require positive method advertisement before enabling edits — ui/src/pages/chat/components/chat-session-workspace.ts:422
    When hello.features.methods is absent, isGatewayMethodAdvertised returns null, and !== false still exposes Edit. Older or metadata-omitting gateways can enter edit mode and fail only on save; require === true for this new mutation capability.
    Confidence: 0.99
  • [P2] Route Markdown through the editable file view — ui/src/pages/chat/components/chat-session-workspace.ts:412-417
    The Markdown early return runs before the edit payload is built, so ordinary .md, .markdown, and .mdx opens never show Edit. That misses the stated document-correction workflow; preserve rendered Markdown as a view option, but route editable files through the canonical editor path.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 2e6c1090c1d4.

Label changes

Label justifications:

  • P2: This is a substantial feature with bounded correctness and contract blockers, not an urgent user-facing regression.
  • merge-risk: 🚨 compatibility: The current edit gate enables mutation UI when method advertisement is unavailable, breaking the promised older-gateway read-only fallback.
  • merge-risk: 🚨 security-boundary: The PR adds remote admin overwrites of existing workspace files and deliberately accepts a short external-writer race.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR shows mock-Gateway screenshots and automated coverage, but not after-fix edit, save, and stale-conflict behavior against a real Gateway workspace. Add a redacted real-Gateway recording or live diagnostic transcript; after updating the PR body, review should rerun automatically, or a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The PR shows mock-Gateway screenshots and automated coverage, but not after-fix edit, save, and stale-conflict behavior against a real Gateway workspace. Add a redacted real-Gateway recording or live diagnostic transcript; after updating the PR body, review should rerun automatically, or a maintainer can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +997, Tests +430, Docs +1, Config +6, Other +589. Total +2023 across 28 files.

View PR surface stats
Area Files Added Removed Net
Source 19 1259 262 +997
Tests 4 477 47 +430
Docs 1 1 0 +1
Config 1 6 0 +6
Generated 0 0 0 0
Other 3 591 2 +589
Total 28 2334 311 +2023

Security concerns:

  • [medium] Own the check-then-write race bound — src/gateway/server-methods/sessions-files.ts:742
    The handler validates the hash and then performs a separate write, so an external process can change the file during that window and be overwritten; the permanent security-sensitive contract needs explicit maintainer approval.
    Confidence: 0.97

What I checked:

Likely related people:

  • steipete: Current-main history ties the existing file-viewer and session-file behavior to commit 724e90c, and they authored the linked feature issue and proposed contract. (role: recent feature owner; confidence: high; commits: 724e90c3c820, 0b02147150b7, 56bf5e3841d3; files: src/gateway/server-methods/sessions-files.ts, ui/src/pages/chat/components/chat-session-workspace.ts, ui/src/pages/chat/components/chat-sidebar.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (2 earlier review cycles)
  • reviewed 2026-07-11T23:01:14.404Z sha dfbc9f5463d33e616713cf2ac80eb32f14a62f19 :: needs real behavior proof before merge. :: [P2] Route Markdown files through the editable file view | [P1] Make the hash check and file replacement conflict-safe
  • reviewed 2026-07-11T23:16:33.999Z sha 69142a4da7748b300555df61ea6575d79faa7c1f :: needs real behavior proof before merge. :: [P1] Make hash validation atomic with file replacement | [P2] Route Markdown files through the editable file view

@clawsweeper clawsweeper Bot added proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Jul 11, 2026
@steipete
steipete force-pushed the claude/file-preview-edit-syntax-2cce6d branch from 69142a4 to 262b643 Compare July 12, 2026 00:18

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 262b6437d5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const canEdit =
typeof file.hash === "string" &&
hasUniformLineEndings(file.content) &&
isGatewayMethodAdvertised(state, "sessions.files.set") !== false &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Require sessions.files.set advertisement for edits

When hello.features.methods is absent, isGatewayMethodAdvertised returns null, and this !== false check treats that as permission to show Edit. In that compatibility case the user gets an Edit button for a gateway that may only support sessions.files.get, and the save path then fails with an unknown sessions.files.set request instead of staying read-only; require === true for this new mutation method.

Useful? React with 👍 / 👎.

@steipete
steipete merged commit 82667a6 into main Jul 12, 2026
165 of 166 checks passed
@steipete
steipete deleted the claude/file-preview-edit-syntax-2cce6d branch July 12, 2026 00:36
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 12, 2026
…hash-CAS writes (openclaw#104757)

* feat(gateway): add sessions.files.set workspace file write with hash CAS (openclaw#104698)

* feat(ui): CodeMirror file editor panel with CAS save + clickable tool-card paths (openclaw#104698)

* fix(gateway): issue the file CAS hash only for strict-UTF-8 text (openclaw#104698)

* docs(web): document the editable file detail panel (openclaw#104698)

* fix(gateway,ui): round-trip BOM and CRLF bytes through the file editor (openclaw#104698)

* fix(ui): keep mixed-line-ending files read-only in the file editor (openclaw#104698)

* fix(ui): re-gate editability when a conflict reload returns non-editable content (openclaw#104698)

* fix(gateway): reject NUL bytes in sessions.files.set replacement content (openclaw#104698)

* fix(gateway,ui): regenerate protocol bindings, fix prod types and lint for file editor (openclaw#104698)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui dependencies-changed PR changes dependency-related files docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Editable file panel in Control UI (sessions.files.set with hash CAS + CodeMirror editor)

1 participant