Skip to content

Commit 82667a6

Browse files
authored
feat(ui): editable file panel with CodeMirror and sessions.files.set hash-CAS writes (#104757)
* feat(gateway): add sessions.files.set workspace file write with hash CAS (#104698) * feat(ui): CodeMirror file editor panel with CAS save + clickable tool-card paths (#104698) * fix(gateway): issue the file CAS hash only for strict-UTF-8 text (#104698) * docs(web): document the editable file detail panel (#104698) * fix(gateway,ui): round-trip BOM and CRLF bytes through the file editor (#104698) * fix(ui): keep mixed-line-ending files read-only in the file editor (#104698) * fix(ui): re-gate editability when a conflict reload returns non-editable content (#104698) * fix(gateway): reject NUL bytes in sessions.files.set replacement content (#104698) * fix(gateway,ui): regenerate protocol bindings, fix prod types and lint for file editor (#104698)
1 parent 39e2da5 commit 82667a6

28 files changed

Lines changed: 2334 additions & 311 deletions

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3434,6 +3434,7 @@ public struct SessionFileEntry: Codable, Sendable {
34343434
public let size: Int?
34353435
public let updatedatms: Int?
34363436
public let content: String?
3437+
public let hash: String?
34373438

34383439
public init(
34393440
path: String,
@@ -3443,7 +3444,8 @@ public struct SessionFileEntry: Codable, Sendable {
34433444
missing: Bool,
34443445
size: Int? = nil,
34453446
updatedatms: Int? = nil,
3446-
content: String? = nil)
3447+
content: String? = nil,
3448+
hash: String? = nil)
34473449
{
34483450
self.path = path
34493451
self.workspacepath = workspacepath
@@ -3453,6 +3455,7 @@ public struct SessionFileEntry: Codable, Sendable {
34533455
self.size = size
34543456
self.updatedatms = updatedatms
34553457
self.content = content
3458+
self.hash = hash
34563459
}
34573460

34583461
private enum CodingKeys: String, CodingKey {
@@ -3464,6 +3467,7 @@ public struct SessionFileEntry: Codable, Sendable {
34643467
case size
34653468
case updatedatms = "updatedAtMs"
34663469
case content
3470+
case hash
34673471
}
34683472
}
34693473

@@ -3563,6 +3567,58 @@ public struct SessionsFilesGetResult: Codable, Sendable {
35633567
}
35643568
}
35653569

3570+
public struct SessionsFilesSetParams: Codable, Sendable {
3571+
public let sessionkey: String
3572+
public let path: String
3573+
public let agentid: String?
3574+
public let content: String
3575+
public let expectedhash: String
3576+
3577+
public init(
3578+
sessionkey: String,
3579+
path: String,
3580+
agentid: String? = nil,
3581+
content: String,
3582+
expectedhash: String)
3583+
{
3584+
self.sessionkey = sessionkey
3585+
self.path = path
3586+
self.agentid = agentid
3587+
self.content = content
3588+
self.expectedhash = expectedhash
3589+
}
3590+
3591+
private enum CodingKeys: String, CodingKey {
3592+
case sessionkey = "sessionKey"
3593+
case path
3594+
case agentid = "agentId"
3595+
case content
3596+
case expectedhash = "expectedHash"
3597+
}
3598+
}
3599+
3600+
public struct SessionsFilesSetResult: Codable, Sendable {
3601+
public let sessionkey: String
3602+
public let root: String?
3603+
public let file: SessionFileEntry
3604+
3605+
public init(
3606+
sessionkey: String,
3607+
root: String? = nil,
3608+
file: SessionFileEntry)
3609+
{
3610+
self.sessionkey = sessionkey
3611+
self.root = root
3612+
self.file = file
3613+
}
3614+
3615+
private enum CodingKeys: String, CodingKey {
3616+
case sessionkey = "sessionKey"
3617+
case root
3618+
case file
3619+
}
3620+
}
3621+
35663622
public struct SessionDiffFile: Codable, Sendable {
35673623
public let path: String
35683624
public let oldpath: String?

‎docs/web/control-ui.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ The macOS app keeps its native link-browser sidebar for links clicked in the das
309309
- When a session's checkout sits on a non-default branch of a GitHub repository, the chat view pins pull request chips above the composer: PR number, repo, branch, diff counts, a CI pill, and draft/merged/closed state, each linking to the PR. The row shows at most two chips — live (open/draft) PRs first — and a "Show more" button reveals collapsed merged/closed history. The CI pill opens a small CI monitoring popover with passed/failed/running/skipped check counts and a link to the PR's checks page. Detection runs server-side through `controlUi.sessionPullRequests`, which reuses the Gateway's `GH_TOKEN`/`GITHUB_TOKEN` when set. When the GitHub API rate limit is hit, chips keep the last known status and show a warning that the status may be out of date; dismissing a chip hides it for that session in the current browser profile.
310310
- The session diff panel shows what a session's checkout actually changed: the branch button (in the workspace rail header, the split-pane header, or the floating button in single-pane chat) opens the detail panel with a per-file diff of branch, uncommitted, and untracked work against the checkout's default-branch merge base — status dot, rename arrow, per-file +/− counts, collapsible files, and "N unmodified lines" markers between hunks. Diffs are computed server-side through the `sessions.diff` Gateway method (`operator.read` scope); binary and oversized files degrade to stats-only entries, and the button only appears when the connected Gateway advertises `sessions.diff`.
311311
- The session workspace rail in each Chat pane lists session files, project files, and artifacts. It docks to the pane's right edge by default; drag its header (or use the dock button) to move it to the bottom, and the choice is stored in the current browser profile. A collapsed rail takes no space at all: reopen it with ⇧⌘B, the files toggle in the split-pane header, or the floating files button in single-pane chat (both carry a changed-file count badge). The separate file, tool, and Canvas detail panel is unaffected.
312+
- Clicking a file reference in chat, a file path in an expanded read/edit/write tool card, or a file row in the workspace rail opens the file detail panel: a CodeMirror-based code view with syntax highlighting, line numbers, jump-to-line, in-file search, copy actions, and an open-in-external-editor menu. When the Gateway advertises `sessions.files.set` to an `operator.admin` connection, the panel adds an Edit mode with dirty tracking and Cmd/Ctrl-S save. Saves are compare-and-swap on a content hash returned by `sessions.files.get`: if the file changed on disk since it was loaded (for example because the agent kept working), the panel shows a conflict notice with Reload (take the latest content) and Overwrite (keep the local edit) actions. Writes go through the same fs-safe workspace guards as reads — path containment, symlink/hardlink rejection, and a 256 KB UTF-8 cap — and only overwrite existing files; the editor never creates or deletes them.
312313
- The background tasks rail in each Chat pane lists the current agent's background tasks and subagents (`tasks.list` scoped by agent, kept live by `task` events): running work shows a live elapsed timer, tool-use count, the tool currently in use, and a stop control; the collapsible finished section adds run durations; and a View transcript link opens the task's child session in the pane. Open it with the activity toggle in the split-pane header or the floating activity button in single-pane chat — the task snapshot loads eagerly, so both carry a running-count badge without opening the rail first. The Tasks page remains the full cross-agent ledger.
313314
- The workspace rail, background tasks rail, and detail panel adapt to each pane's own width rather than the window: in a narrow pane or compact window both rails present as bottom strips (side-dock controls hide until the pane widens; the workspace rail keeps first claim on the side slot when only one column fits), and the detail panel stacks below the thread with a horizontal resize handle instead of sharing the row with it. Phone-sized viewports still open the detail panel full-screen.
314315
- The chat header model and thinking pickers patch the active session immediately through `sessions.patch`; they are persistent session overrides, not one-turn-only send options.

‎packages/gateway-protocol/src/index.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,10 @@ import {
633633
SessionsFilesGetParamsSchema,
634634
type SessionsFilesGetResult,
635635
SessionsFilesGetResultSchema,
636+
type SessionsFilesSetParams,
637+
SessionsFilesSetParamsSchema,
638+
type SessionsFilesSetResult,
639+
SessionsFilesSetResultSchema,
636640
type SessionsFilesListParams,
637641
SessionsFilesListParamsSchema,
638642
type SessionsFilesListResult,
@@ -1160,6 +1164,9 @@ export const validateSessionsFilesListParams = lazyCompile<SessionsFilesListPara
11601164
export const validateSessionsFilesGetParams = lazyCompile<SessionsFilesGetParams>(
11611165
SessionsFilesGetParamsSchema,
11621166
);
1167+
export const validateSessionsFilesSetParams = lazyCompile<SessionsFilesSetParams>(
1168+
SessionsFilesSetParamsSchema,
1169+
);
11631170
export const validateSessionsDiffParams = lazyCompile<SessionsDiffParams>(SessionsDiffParamsSchema);
11641171
export const validateSessionsCreateParams = lazyCompile<SessionsCreateParams>(
11651172
SessionsCreateParamsSchema,
@@ -1689,6 +1696,8 @@ export {
16891696
SessionFileRelevanceSchema,
16901697
SessionsFilesGetParamsSchema,
16911698
SessionsFilesGetResultSchema,
1699+
SessionsFilesSetParamsSchema,
1700+
SessionsFilesSetResultSchema,
16921701
SessionsFilesListParamsSchema,
16931702
SessionsFilesListResultSchema,
16941703
SessionDiffFileSchema,
@@ -2116,6 +2125,8 @@ export type {
21162125
SessionsFilesListResult,
21172126
SessionsFilesGetParams,
21182127
SessionsFilesGetResult,
2128+
SessionsFilesSetParams,
2129+
SessionsFilesSetResult,
21192130
SessionDiffFile,
21202131
SessionDiffFileStatus,
21212132
SessionsDiffParams,

‎packages/gateway-protocol/src/schema/protocol-schemas.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ import {
411411
SessionsFilesGetResultSchema,
412412
SessionsFilesListParamsSchema,
413413
SessionsFilesListResultSchema,
414+
SessionsFilesSetParamsSchema,
415+
SessionsFilesSetResultSchema,
414416
SessionsListParamsSchema,
415417
SessionsMessagesSubscribeParamsSchema,
416418
SessionsMessagesUnsubscribeParamsSchema,
@@ -630,6 +632,8 @@ export const ProtocolSchemas = {
630632
SessionsFilesListResult: SessionsFilesListResultSchema,
631633
SessionsFilesGetParams: SessionsFilesGetParamsSchema,
632634
SessionsFilesGetResult: SessionsFilesGetResultSchema,
635+
SessionsFilesSetParams: SessionsFilesSetParamsSchema,
636+
SessionsFilesSetResult: SessionsFilesSetResultSchema,
633637
SessionDiffFileStatus: SessionDiffFileStatusSchema,
634638
SessionDiffFile: SessionDiffFileSchema,
635639
SessionsDiffParams: SessionsDiffParamsSchema,

‎packages/gateway-protocol/src/schema/sessions.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export const SessionFileEntrySchema = Type.Object(
8585
size: Type.Optional(Type.Integer({ minimum: 0 })),
8686
updatedAtMs: Type.Optional(Type.Integer({ minimum: 0 })),
8787
content: Type.Optional(Type.String()),
88+
hash: Type.Optional(NonEmptyString),
8889
},
8990
{ additionalProperties: false },
9091
);
@@ -156,6 +157,28 @@ export const SessionsFilesGetResultSchema = Type.Object(
156157
{ additionalProperties: false },
157158
);
158159

160+
/** Overwrites one existing session workspace file with hash-based CAS. */
161+
export const SessionsFilesSetParamsSchema = Type.Object(
162+
{
163+
sessionKey: NonEmptyString,
164+
path: NonEmptyString,
165+
agentId: Type.Optional(NonEmptyString),
166+
content: Type.String(),
167+
expectedHash: NonEmptyString,
168+
},
169+
{ additionalProperties: false },
170+
);
171+
172+
/** Result for overwriting one session workspace file. */
173+
export const SessionsFilesSetResultSchema = Type.Object(
174+
{
175+
sessionKey: NonEmptyString,
176+
root: Type.Optional(NonEmptyString),
177+
file: SessionFileEntrySchema,
178+
},
179+
{ additionalProperties: false },
180+
);
181+
159182
/** Change status for one file in a session checkout diff. */
160183
export const SessionDiffFileStatusSchema = Type.Union([
161184
Type.Literal("added"),

‎packages/gateway-protocol/src/schema/types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ export type SessionsFilesListParams = SchemaType<"SessionsFilesListParams">;
420420
export type SessionsFilesListResult = SchemaType<"SessionsFilesListResult">;
421421
export type SessionsFilesGetParams = SchemaType<"SessionsFilesGetParams">;
422422
export type SessionsFilesGetResult = SchemaType<"SessionsFilesGetResult">;
423+
export type SessionsFilesSetParams = SchemaType<"SessionsFilesSetParams">;
424+
export type SessionsFilesSetResult = SchemaType<"SessionsFilesSetResult">;
423425
export type SessionDiffFileStatus = SchemaType<"SessionDiffFileStatus">;
424426
export type SessionDiffFile = SchemaType<"SessionDiffFile">;
425427
export type SessionsDiffParams = SchemaType<"SessionsDiffParams">;

0 commit comments

Comments
 (0)