Repository navigation
web-ui: workspace.zip export + import - #312
Conversation
Adds a "⬇ workspace.zip" button to the Settings bar that downloads $PASCLAW_HOME/workspace as a zip, mirroring what `pasclaw build` packs for portability/backup. Server: GET /v1/workspace/export packs workspace/ via PackDirToZip (excluding .git/.DS_Store/Thumbs.db/kb.db-journal) to a temp zip at the home root, reads it into memory, deletes the temp file, and streams it as application/zip with Content-Disposition: attachment. Security: deliberately scoped to workspace/ ONLY (not the whole $PASCLAW_HOME), so config.json secrets and oauth tokens at the home root are never shipped -- a deliberate divergence from `pasclaw build`. UI: gwFetch carries the bearer token, so the client fetches -> blob -> synthetic <a download> rather than a plain link. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e8bfbabb99
ℹ️ 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".
| end; | ||
| ZipPath := JoinPath(GetHome, | ||
| 'workspace-export-' + FormatDateTime('yyyymmdd-hhnnss', Now) + '.zip'); | ||
| if not PackDirToZip(WsDir, ZipPath, ExcludeFromZip, Err) then |
There was a problem hiding this comment.
Keep exported files inside the workspace
This endpoint relies on PackDirToZip(WsDir, ...) as the security boundary, but the packer only walks names and adds each path to the archive; it does not reject links or realpath-check files. If workspace/ contains a link such as leak -> ../config.json or another secret outside the workspace, the zip library opens the target and the download includes those bytes, contradicting the promise that home-root secrets/oauth tokens are never shipped. Please skip links or validate each resolved file/inode before zipping.
Useful? React with 👍 / 👎.
| <button class="primary" id="config-save">Save</button> | ||
| <button class="icon-btn" id="config-reload">Reload</button> | ||
| <button class="icon-btn" id="config-raw-toggle" title="Toggle the raw JSON editor (for adding/removing array entries the form can't)">Raw JSON</button> | ||
| <button class="icon-btn" id="ws-export" title="Download workspace/ (memory, skills, KB, sessions) as a zip. Secrets in config.json are NOT included.">⬇ workspace.zip</button> |
There was a problem hiding this comment.
Regenerate the embedded web UI resource
The gateway serves this page from the compiled src/pkg/gateway/webui.res resource (WebUIStream opens PASCLAW_WEBUI_HTML), but that tracked resource is unchanged in this commit and does not contain ws-export or /v1/workspace/export. In builds that link the checked-in resource without first rebuilding it, such as Delphi/direct FPC project builds or a checkout where make sees the .res as newer than webui.html, the Settings page remains the old UI and the export button is absent even though the route exists. Please commit the regenerated webui.res with this HTML change.
Useful? React with 👍 / 👎.
Counterpart to the export button. A "⬆ import zip" button uploads a workspace.zip and overlays it onto $PASCLAW_HOME/workspace. Server: POST /v1/workspace/import accepts a raw application/zip body (capped at 512 MB), saves it to a temp file at the home root, and calls ExtractZipToDir into workspace/. Entry validation (zip-slip guard) runs before anything is written, so "../config.json" or absolute-path entries are rejected -- import cannot escape workspace/ to clobber config.json secrets. Merge semantics: archive files overwrite their counterparts; existing files the archive doesn't mention are kept. UI: hidden file input + confirm() prompt; POSTs the file bytes via gwFetch (bearer token) and reports the server's note. Reminds the user to restart serve/gateway to pick up newly imported skills. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
Export now stores entries under a top-level workspace/ dir (via a new optional ArchivePrefix arg on PackDirToZip), so a web-exported workspace.zip has the same shape as `pasclaw build --workspace-out` and drops straight into `pasclaw build --workspace-in`. Import is reworked to match: the canonical zip carries a workspace/ prefix, so unzipping directly into workspace/ would nest workspace/workspace/. Instead import extracts to a staging dir at the home root and merge-copies ONLY staging/workspace -> home/workspace (falling back to the whole tree for a bare, prefix-less zip). This also means a full `pasclaw build` zip (which has sessions/, config.json, etc. at the root) imports cleanly -- only its workspace/ is taken, so a stray config.json in the upload can never overwrite the running server's secrets. Adds portable recursive copy/delete helpers (no fileutil / IOUtils dependency). Test: TestArchivePrefix in build_workspace_roundtrip_tests asserts prefixed entries land under workspace/ and never at the root. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
The README + docs/changelog.md last entry was 2026-06-13 (FMXExpress#244). Five substantial PRs (FMXExpress#314 FMXExpress#315 FMXExpress#316 FMXExpress#317 FMXExpress#318) and ten more feature PRs between them and that entry shipped without changelog entries. This brings both files current through today. Twenty new entries (newest first, matching the existing style): 2026-06-21 FMXExpress#318 Relay pull-worker provider (queue + provider + /v1/relay/* HTTP) 2026-06-20 FMXExpress#317 pasclaw plan + build PLAN.md pickup + build --goal + cog mode FMXExpress#316 Cloudflare AI Gateway provider catalog rows FMXExpress#315 MCP progressive disclosure + tool_search FMXExpress#314 Stock defaults adopt lean-edit shape; fs_grep split-gate 2026-06-18 FMXExpress#312 Web UI workspace.zip export + import FMXExpress#310 Model-callable cron tool FMXExpress#309 FTS5 snippet window widened 24 -> 60 FMXExpress#307 Windows cmd.exe quoting fix 2026-06-17 FMXExpress#306 cog-build honours profile=security sandbox FMXExpress#304 cog-build default profile = max-build FMXExpress#303 cog-build list[Path] outputs + Secret inputs + -q 2026-06-16 FMXExpress#302 cog-build optional workspace_in FMXExpress#300 pasclaw build cmd + cog-build/ predictor (parent feature) FMXExpress#299 Checkpoints zpaq backend + /redo FMXExpress#298 AGENTS.md + pasclaw init + /init FMXExpress#297 tool_choice force-a-specific-tool form FMXExpress#296 Delphi ExtraEnv injection fix FMXExpress#295 KB native PDF ingest 2026-06-15 FMXExpress#292 pasclaw profile diff + bench Skipped per the changelog's stated convention ("Bug fixes and review follow-ups are in the full git log"): FMXExpress#293 cmd/profile dcc64 fix FMXExpress#294 skills_manage gemini empty-enum fix FMXExpress#301 cmd.build dcc64 fix FMXExpress#311 cron dcc64 fix Files updated identically (the docs/changelog.md note at the top says "This file mirrors the changelog section at the top of the root README.md"): M README.md 20 entries + 20 link refs added M docs/changelog.md same The link-ref block at the bottom of each file gained 20 [#NNN] entries keeping the existing one-per-line / sorted-numerically format.
What
Adds export and import buttons to the Settings bar so users can back up / restore / move their agent's working state (memory, skills, KB, sessions) from the browser — and the zip is interchangeable with
pasclaw build.$PASCLAW_HOME/workspaceas a zip with a top-levelworkspace/dir.workspace/contents ontoworkspace/.Zip structure (matches
pasclaw build)The export stores entries under a top-level
workspace/directory — the same layoutpasclaw build --workspace-outproduces (it packs the whole$PASCLAW_HOME, whereworkspace/is one of the top-level dirs). So a web-exportedworkspace.zipdrops straight intopasclaw build --workspace-inand vice-versa.Implemented via a new optional
ArchivePrefixarg onPackDirToZip(default''keeps the old relative-to-SrcDir naming, sopasclaw build's own call is unchanged).How
Export —
GET /v1/workspace/export:PackDirToZip(home/workspace, …, ArchivePrefix='workspace'), excluding.git,.DS_Store,Thumbs.db,kb.db-journal.application/zipwithContent-Disposition: attachment.Import —
POST /v1/workspace/import:application/zipbody (capped at 512 MB) saved to a temp file, extracted to a staging dir at the home root, then merge-copies onlystaging/workspace→home/workspace(falls back to the whole tree for a bare, prefix-less zip).fileutil/IOUtilsdependency); staging dir + temp zip cleaned up regardless of outcome.UI: both use
gwFetch(bearer token). Export does fetch →blob()→ synthetic<a download>; import POSTs the file bytes behind aconfirm()prompt.Security
workspace/, never the whole$PASCLAW_HOME.config.json(API keys, oauth tokens) lives at the home root, a sibling ofworkspace/, so secrets are never shipped. (Context:pasclaw buildpacks the whole home — fine there, since on Replicate the home is a fresh temp dir with keys passed via env and no config.json written into it. But the web UI runs underpasclaw serve, whose home is the real~/.pasclawwith config.json present — so the web export must scope toworkspace/.)ExtractZipToDirzip-slip-validates every entry; import then copies only theworkspace/subtree intohome/workspace, so even a fullpasclaw buildzip containing a root-levelconfig.json/sessions/imports just itsworkspace/— a strayconfig.jsonin the upload can never overwrite the running server's secrets.Verification
make allclean;webui.resre-embeds both buttons (verified in the linked binary).make test-build-roundtrippasses, including a newTestArchivePrefixasserting prefixed entries land underworkspace/and never at the destination root. DefaultPackDirToZipbehavior (no prefix) unchanged — existing roundtrip/zip-slip suite still green.Note
Imported skills/config apply on the next
serve/gatewayrestart (the UI says so). Import merges (never wipes unrelated existing workspace files).🤖 Generated with Claude Code