Skip to content

web-ui: workspace.zip export + import - #312

Merged
FMXExpress merged 4 commits into
mainfrom
claude/web-workspace-export
Jun 19, 2026
Merged

FMXExpress merged 4 commits into
mainfrom
claude/web-workspace-export

Conversation

@FMXExpress

@FMXExpress FMXExpress commented Jun 19, 2026 •

Copy link
Copy Markdown
Owner

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.

  • ⬇ workspace.zip — downloads $PASCLAW_HOME/workspace as a zip with a top-level workspace/ dir.
  • ⬆ import zip — uploads a workspace.zip and overlays its workspace/ contents onto workspace/.

Zip structure (matches pasclaw build)

The export stores entries under a top-level workspace/ directory — the same layout pasclaw build --workspace-out produces (it packs the whole $PASCLAW_HOME, where workspace/ is one of the top-level dirs). So a web-exported workspace.zip drops straight into pasclaw build --workspace-in and vice-versa.

Implemented via a new optional ArchivePrefix arg on PackDirToZip (default '' keeps the old relative-to-SrcDir naming, so pasclaw 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.
  • Temp zip at the home root → read into memory → temp deleted → streamed as application/zip with Content-Disposition: attachment.

Import — POST /v1/workspace/import:

  • Raw application/zip body (capped at 512 MB) saved to a temp file, extracted to a staging dir at the home root, then merge-copies only staging/workspace → home/workspace (falls back to the whole tree for a bare, prefix-less zip).
  • Merge semantics: archive files overwrite their counterparts; existing files the archive doesn't mention are kept.
  • Portable recursive copy/delete helpers (no fileutil / IOUtils dependency); 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 a confirm() prompt.

Security

  • Export packs only workspace/, never the whole $PASCLAW_HOME. config.json (API keys, oauth tokens) lives at the home root, a sibling of workspace/, so secrets are never shipped. (Context: pasclaw build packs 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 under pasclaw serve, whose home is the real ~/.pasclaw with config.json present — so the web export must scope to workspace/.)
  • Import can't touch secrets or escape the workspace. ExtractZipToDir zip-slip-validates every entry; import then copies only the workspace/ subtree into home/workspace, so even a full pasclaw build zip containing a root-level config.json/sessions/ imports just its workspace/ — a stray config.json in the upload can never overwrite the running server's secrets.

Verification

  • make all clean; webui.res re-embeds both buttons (verified in the linked binary).
  • make test-build-roundtrip passes, including a new TestArchivePrefix asserting prefixed entries land under workspace/ and never at the destination root. Default PackDirToZip behavior (no prefix) unchanged — existing roundtrip/zip-slip suite still green.

Note

Imported skills/config apply on the next serve/gateway restart (the UI says so). Import merges (never wipes unrelated existing workspace files).

🤖 Generated with Claude Code

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

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment thread src/pkg/gateway/webui.html Outdated
<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>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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
@FMXExpress FMXExpress changed the title web-ui: add workspace.zip export download web-ui: workspace.zip export + import Jun 19, 2026
claude added 2 commits June 19, 2026 02:56
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
@FMXExpress
FMXExpress merged commit 20e097c into main Jun 19, 2026
khongten001 pushed a commit to khongten001/PasClaw that referenced this pull request Jul 13, 2026
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.
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