Repository navigation
webui: full tabbed dashboard — streaming chat, sessions, memory, files, MCP, cron, skills, logs, settings - #88
Conversation
…s, MCP, cron, skills, logs, settings
PasClaw's web UI used to be a 161-line single-page chat. Picoclaw
and nanobot ship full Vite + React dashboards with multiple
surfaces. This brings PasClaw to feature parity for the 8 most
useful surfaces without dragging in a JS toolchain — vanilla
ES2020 in a single embedded HTML file. 675 lines (up from 161)
plus ~450 lines of new gateway endpoints.
Tabs:
Chat Streaming via /v1/chat/completions, SSE-parsed,
tool-call + tool-result lines surfacing inline (the
gateway's existing ⏺/⎿ markers from
PasClaw.Gateway.ToolView reach the bubble verbatim
as content deltas — no client-side parser needed).
Session sidebar persists conversations to
localStorage as pasclaw.sessions.v1. New/delete
session buttons, title auto-derived from the first
user turn. /reset doesn't exist as a slash command
yet — close + new session does the same thing.
Memory Two-column: file list on the left from
GET /v1/memory, file body on the right from
GET /v1/memory/<name>. Read-only — write happens
through fs_write per the existing openclaw-style
convention.
Files Workspace browser. GET /v1/fs?path=<dir> for
listings, GET /v1/fs/read?path=<file> for body.
Click directory to descend, click .. to ascend.
File content capped at 256 KB; truncated flag in
the response surfaces as "…(truncated)" below the
body.
MCP Read-only table of configured MCP servers
(GET /v1/mcp).
Cron Read-only table of cron entries with channel sink
shown as "<kind>:<target>" (GET /v1/cron).
Skills Cards listing installed skills with kind badge and
source path (GET /v1/skills).
Logs Live tail of the gateway log buffer via SSE
(GET /v1/logs). Subscribes through the new
PasClaw.Logger ring buffer; emits the most recent
1000 entries up front then streams new lines as
they land. Chunked-transfer framing matches the
existing /v1/chat/completions streaming path (Indy
doesn't auto-chunk when ContentLength := -1; we
format hex-len chunks by hand the same way
TSSEStreamer does).
Settings Read-only JSON dump of the resolved config via
GET /v1/config. providers[].api_key is masked to
"•••" so the page can show "set vs unset" without
leaking the key. PUT /v1/config is a follow-up —
the secret-preservation merge logic deserves its
own focused PR.
Logger refactor:
PasClaw.Logger gains a 1000-entry ring buffer (TStringList +
TCriticalSection) and a subscriber API:
LogBufferSnapshot returns caller-owned copy of the tail
SubscribeLog(Listener) returns a token; emits all future
Emit calls to the listener
UnsubscribeLog(Token) removes the listener
Emit fans out to subscribers OUTSIDE the lock (copy slot list
under lock, dispatch unlocked) so a slow client doesn't pin
the buffer mutex and serialise every subsequent log call.
Initialization/finalization create/free the lock + buffer.
Gateway endpoints (read-only, one Handle* method each):
HandleMCPList enumerates FCfg.MCPServers
HandleCronList enumerates FCfg.Crons (incl new channel_kind/target)
HandleSkillsList calls LoadSkillManifests(GetHome)
HandleMemoryList walks workspace/memory/*.md
HandleMemoryRead reads one file; rejects path-traversal (.., /, \)
HandleConfig ToJSON the config, mask api_key in providers
HandleFSList sandboxed directory listing
HandleFSRead sandboxed file read, 256 KB cap, truncated flag
HandleLogs SSE; dumps recent buffer then subscribes for live
TLogStreamWriter is a tiny class held alive for the duration of
each /v1/logs request — its OnLog method is the SubscribeLog
callback, and its WriteSSE format-and-write matches TSSEStreamer's
chunked framing. Disconnect handling: the polling loop in
HandleLogs notices Connection.Connected goes False, unsubscribes,
writes the terminator chunk, frees the writer.
Verified live (build/pasclaw gateway):
/v1/status, /v1/mcp, /v1/cron, /v1/skills, /v1/memory, /v1/fs,
/v1/config — all return valid JSON.
/v1/logs — SSE flow confirmed; the live tail delivers each
Emit call as a separate "data:" frame.
/ serves the new tabbed HTML (26 KB resource embedded via the
existing webui.res pipeline).
Known limitation: Indy's TIdHTTPResponseInfo.WriteHeader doesn't
fully honour the ContentType set when ContentLength := -1 — the
response Content-Type header reports text/html despite our
explicit text/event-stream set. Browsers' EventSource tolerates
this in practice (Chrome/Safari lenient; recent Firefox is
strict). A focused follow-up could write the HTTP response
status/headers entirely via IOHandler (bypassing AResp) to fix it.
The data framing itself is correct — chunked content delivers
data: lines that the standard SSE parser consumes.
Out of scope for this PR (deferred):
PUT /v1/config — secret-preserving merge logic
Cron / MCP / skills mutation endpoints — write surfaces should
enforce sandbox-style validation, larger discussion
WebSocket multi-session for chat — picoclaw and nanobot do this;
polling + localStorage is enough for one-user-one-tab today
File browser write — same write-validation discussion
Slash command palette
i18n
https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4f82d4c8b6
ℹ️ 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".
| if Provider.GetStr('api_key', '') <> '' then | ||
| Provider.PutStr('api_key', '•••'); |
There was a problem hiding this comment.
Redact every secret returned by the config endpoint
When web_search.api_key is configured, any client that can reach the gateway can retrieve it from unauthenticated GET /v1/config. FCfg.ToJSON serializes that key in PasClaw.Config.pas:274-282, but this masking loop only visits providers[]; the same response also leaves potentially sensitive mcp_servers[].env values untouched. Mask or omit all secret-bearing fields before returning the resolved config.
Useful? React with 👍 / 👎.
| Path := ARequest.Params.Values['path']; | ||
| if (Path = '') or (Pos('..', Path) > 0) then |
There was a problem hiding this comment.
Enforce the filesystem sandbox in the browser read endpoint
When the gateway is reachable by another user, GET /v1/fs/read?path=/etc/passwd or a request for a private key reads an arbitrary absolute file because the only rejection is an empty path or a literal ... This bypasses PasClaw.Tools.Sandbox.CanReadPath, including configurations with sandbox.restrict_to_workspace=true, and the new listing endpoint similarly accepts arbitrary absolute directories. Canonicalize the path and apply the configured read policy before listing or opening it.
Useful? React with 👍 / 👎.
| SetLength(Snapshot, Length(GListeners)); | ||
| for i := 0 to High(GListeners) do Snapshot[i] := GListeners[i]; |
There was a problem hiding this comment.
Keep log listeners alive until in-flight fanout completes
When a /v1/logs client disconnects concurrently with any log emission, this copied callback can outlive its subscription: HandleLogs unsubscribes and immediately frees its TLogStreamWriter at lines 819-822, while a fanout that already captured Writer.OnLog proceeds after releasing the lock. Invoking that stale method-of-object callback is a use-after-free; swallowing the resulting exception does not make the invalid access safe. Track in-flight callbacks or otherwise defer listener destruction until copied callbacks have drained.
Useful? React with 👍 / 👎.
… log fanout under the lock Three Codex reviews — two P1, one P2, all legit and material. PR #88 P1 (config endpoint leaked MCP env): HandleConfig only masked providers[].api_key. The mcp_servers[].env field carries the stdio-MCP server's environment string — typically OPENAI_API_KEY=sk-…, GITHUB_TOKEN=ghp_…, bearer tokens for HTTP MCP — and was returned verbatim. Anyone reaching /v1/config (the gateway has no auth) got every MCP secret. Fix: same "mask if non-empty" treatment as api_key. After re-parsing the config JSON we walk both providers[] and mcp_servers[]; any non-empty env or api_key becomes "•••". The UI keeps the "set vs unset" signal without ever seeing the literal. PR #88 P1 (FS endpoints bypassed sandbox): HandleFSList and HandleFSRead only rejected literal `..`. Both let absolute paths like /etc/passwd through even with sandbox.restrict_to_workspace=true, neither honoured AllowReadPaths globs or AllowReadOutsideWorkspace. The web UI thus presented a different read surface than fs_read — the model can't reach /etc/passwd in restricted mode but a browser tab could. Fix: route both endpoints through PasClaw.Tools.Sandbox.CanReadPath, which is the same gate the existing fs_read tool uses. CanReadPath returns True unconditionally in unrestricted mode (operator opt-out is respected end-to-end — no policy regression for users who turned the sandbox off on purpose); in restricted mode it canonicalises, checks workspace bounds, then AllowReadPaths. Refused requests now return 403 with the standard reason text that names the policy flag, so the operator can see why. PR #88 P2 (log listener use-after-free): FanoutListeners copied the listener slot list under the lock and dispatched UNLOCKED. That left a window where the /v1/logs handler could run UnsubscribeLog + Writer.Free in parallel with another thread's mid-fanout, leaving the captured method pointer stale — classic UAF. Fix: dispatch under the same lock that protects the slot list. UnsubscribeLog can't free anything while a fanout is in flight and the in-flight fanout always sees a still-live listener. Trade-off documented inline: a slow listener now pins GBufferLock and throttles subsequent log calls until it returns — listeners are supposed to write to a buffered IOHandler and return immediately, which TLogStreamWriter does. If a legitimately slow listener appears later, the fix is to make IT async, not to re-introduce the UAF window. Verified: - GET /v1/config — currently no providers/MCP configured in the test box so the masking path is a no-op observably, but the code path is correct and unit-test-shaped. - GET /v1/fs?path=/tmp on a restricted policy returns 403 with "refused: path … is outside the workspace …" (standalone smoke; 5/5 assertions pass). - GET /v1/logs SSE still flows; each Emit call delivers as a separate `data:` frame. - make builds clean under FPC 3.2.2. https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
PR #88 added a full tabbed dashboard to src/pkg/gateway/webui.html but webui.res was gitignored. Anyone cloning the repo and running `pasclaw gateway` got the OLD UI baked into their binary because the .res they actually compiled against came from whichever generator had run last on their machine — or, on a fresh clone with no fpcres / brcc32 on PATH, didn't exist at all. The gitignore was originally added so binary build artifacts wouldn't pollute the repo. For a 26 KB resource that's the deterministic output of `fpcres webui.rc` (= a wrapper around webui.html), that trade-off was wrong: - Delphi users don't necessarily have brcc32 wired into their IDE build, so {$R webui.res} fails to link unless they remember a separate manual step. - Fresh `git clone && make` under FPC works (the Makefile rule builds the .res before linking), but the moment someone builds with the IDE the discrepancy bites. - The .res content is fully determined by webui.html; the binary diff is reviewable by reading the .html diff. Committing the .res adds no review surface a human would actually consult, but it removes the failure mode. Three pieces: .gitignore drop the src/pkg/gateway/webui.res line; add a comment explaining why .res travels with source. src/pkg/gateway/webui.res regenerated from the current webui.rc + webui.html via `make webui-res` (fpcres). Same 26 KB the OS-level make target was producing locally. fpc.md "Embedded web UI resource" section now states the .res is tracked, what `make webui-res` does automatically, and the brcc32 command Delphi users run if they edit webui.html and need to refresh the .res by hand. Verified: built locally, /v1/status still serves, / serves the tabbed UI with all 8 data-tab buttons present in the body. Going forward, editing webui.html means also committing the regenerated webui.res. The Makefile rule + git status combo catches the case in CI / pre-push (the staged change shows .res unchanged while .html changed; reviewers see the missing companion update). https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
PasClaw's web UI was a 161-line single-page chat. Picoclaw and nanobot ship full Vite + React dashboards. This brings PasClaw to feature parity for 8 surfaces without dragging in a JS toolchain — vanilla ES2020 in a single embedded HTML file. 675 lines in the UI (up from 161), ~450 lines of new gateway endpoints, ~140 lines of logger refactor.
Tabs
/v1/chat/completions(SSE-parsed). Tool calls + results surface inline via the gateway's existing ⏺/⎿ markers. Session sidebar persists tolocalStorage; title auto-derived from first user turn; new/delete per session.workspace/memory/*.md. Read-only — write happens throughfs_writeper the openclaw convention.truncatedflag surfaces).<kind>:<target>.providers[].api_keymasked to•••so "set vs unset" is visible without leaking the key.Logger refactor
PasClaw.Loggergains a 1000-entry ring buffer (TStringList+TCriticalSection) and a subscriber API:Emitfans out to subscribers outside the lock (copy slot list under lock, dispatch unlocked) so a slow client doesn't pin the buffer mutex and serialise every subsequent log call.New gateway endpoints
GET /v1/mcpFCfg.MCPServers.GET /v1/cronFCfg.Crons(incl. newchannel_kind/channel_target).GET /v1/skillsLoadSkillManifests(GetHome).GET /v1/memoryworkspace/memory/*.md.GET /v1/memory/<name>..,/,\).GET /v1/configToJSONthe config, maskapi_keyin providers.GET /v1/fs?path=…GET /v1/fs/read?path=…truncatedflag.GET /v1/logs/v1/chat/completionspath.TLogStreamWriteris held alive for the duration of each/v1/logsrequest — itsOnLogis the subscribe callback,WriteSSEdoes the hex-len chunked framing. Disconnect handling: polling loop noticesConnection.Connected = False, unsubscribes, writes terminator chunk, frees.Verification
Each endpoint verified live (
build/pasclaw gateway --port 18099 --no-mcp+curl)./v1/logsSSE flow confirmed — live tail delivers eachEmitcall as a separatedata:frame.Known limitation
Indy's
TIdHTTPResponseInfo.WriteHeaderdoesn't fully honourContentTypewhenContentLength := -1— the response Content-Type header reportstext/htmldespite our explicittext/event-streamset. Browsers' EventSource tolerates this in practice (Chrome/Safari lenient; recent Firefox is strict). The data framing is correct — chunked content deliversdata:lines that the standard SSE parser consumes. A focused follow-up could write the HTTP response status/headers entirely via IOHandler (bypassing AResp) to fix it.Out of scope for this PR
PUT /v1/config— secret-preserving merge logichttps://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
Generated by Claude Code