Skip to content

Feature: Workspace export/import for backup, migration, and sharing #877

Description

@cybermaggedon

Summary

Add CLI commands to export a workspace's full state as a portable bundle, and import it into another deployment. This enables backup/restore, migration between environments (dev → staging → prod), and sharing knowledge bases between teams.

Motivation

Currently there is no way to:

  • Back up a workspace's configuration and knowledge before a risky change
  • Move a workspace from one TrustGraph deployment to another
  • Share a pre-configured workspace (prompts, tools, blueprints, agent patterns) as a starter kit

The building blocks exist — the config API has get_all / put_many, and the knowledge store has query/load interfaces — but there's no user-facing tooling to orchestrate a full export/import.

Proposed design

Please PR against the latest release/vX.Y branch.

Export

tg-export-workspace --workspace default --output workspace-default.tgx

Produces a single archive (e.g. tar.gz or zip) containing:

workspace-default.tgx/
├── manifest.json          # version, workspace id, export timestamp, TG version
├── config/                # all config entries
│   ├── prompt/            # one file per key
│   │   ├── extract-concepts.json
│   │   └── ...
│   ├── tool/
│   ├── flow-blueprint/
│   ├── agent-pattern/
│   ├── agent-task-type/
│   ├── collection/
│   └── ...
└── knowledge/             # optional, flag-controlled
    ├── triples.nq         # N-Quads dump of knowledge graph
    └── embeddings/        # serialised embeddings (format TBD)

Import

tg-import-workspace --input workspace-default.tgx --workspace staging
  • --workspace optionally renames the workspace on import (default: use the name from the manifest)
  • --overwrite flag to control whether existing keys are replaced or skipped (same semantics as WorkspaceInit's overwrite parameter)
  • --config-only flag to skip knowledge import (useful for copying prompt/tool config without the data)

What to export

Phase 1 (config only):

  • All config types: prompts, tools, blueprints, agent patterns, agent task types, collections, MCP configs, parameter types, interface descriptions, token costs
  • This is the most immediately useful part and the simplest to implement

Phase 2 (knowledge):

  • Triples from the knowledge graph (via triples client query)
  • Document content from the librarian
  • Embeddings (graph + document)
  • This is larger in scope and may require streaming for large knowledge bases

Where it fits in the codebase

New CLI commands in trustgraph-cli/trustgraph/cli/:

trustgraph-cli/trustgraph/cli/
├── export_workspace.py    # new
└── import_workspace.py    # new

Both would use the existing gateway API (trustgraph-cli/trustgraph/api/) to interact with config-svc. The config API's get_all endpoint returns everything for a workspace in one call, and put_many can write it back.

Entry points

Add to pyproject.toml:

tg-export-workspace = "trustgraph.cli.export_workspace:main"
tg-import-workspace = "trustgraph.cli.import_workspace:main"

Implementation notes

  • The archive format should be human-readable (JSON files in a directory structure) so users can inspect and hand-edit before importing
  • Config values are stored as JSON strings in config-svc — export them pretty-printed for readability
  • The manifest should include the TrustGraph version so import can warn about version mismatches
  • For Phase 1, this is primarily a CLI exercise — no changes to the backend services needed

What you'll learn

  • How TrustGraph's configuration system stores and retrieves workspace state
  • The gateway API and how CLI tools interact with it
  • How workspaces are structured and what config types exist
  • CLI argument parsing patterns used throughout trustgraph-cli

References

  • Existing CLI commands: trustgraph-cli/trustgraph/cli/ (see list_config_items.py, get_config_item.py, put_config_item.py for patterns)
  • Gateway API client: trustgraph-cli/trustgraph/api/
  • Config client: trustgraph-base/trustgraph/base/config_client.py (especially get_all and put_many)
  • WorkspaceInit (similar overwrite logic): trustgraph-flow/trustgraph/bootstrap/initialisers/workspace_init.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions