From 830959e0dbec5573d9a57d989f9eb17ed31d4df1 Mon Sep 17 00:00:00 2001 From: Cheese Date: Sat, 18 Jul 2026 01:41:33 +0800 Subject: [PATCH 1/3] docs: add tdc preview documentation --- TOC-ai.md | 26 ++ ai/_index.md | 41 +++ .../concepts/tdc-concepts-and-architecture.md | 129 ++++++++ ai/tdc/examples/tdc-agent-sandbox-example.md | 106 ++++++ ai/tdc/examples/tdc-daily-workflow-example.md | 112 +++++++ .../tdc-git-workspace-for-agents-example.md | 83 +++++ .../tdc-journal-agent-workflow-example.md | 84 +++++ .../tdc-query-sql-with-roles-example.md | 103 ++++++ ...hare-filesystem-across-machines-example.md | 100 ++++++ .../tdc-vault-agent-secrets-example.md | 97 ++++++ ai/tdc/guides/tdc-filesystem-git.md | 98 ++++++ ai/tdc/guides/tdc-filesystem-journal.md | 82 +++++ ai/tdc/guides/tdc-filesystem-vault.md | 141 ++++++++ ai/tdc/guides/tdc-filesystem.md | 301 ++++++++++++++++++ ai/tdc/guides/tdc-install-configure-update.md | 148 +++++++++ ai/tdc/guides/tdc-organization.md | 65 ++++ ai/tdc/guides/tdc-starter-database.md | 204 ++++++++++++ ai/tdc/reference/tdc-cli-reference.md | 158 +++++++++ .../tdc-configuration-and-credentials.md | 195 ++++++++++++ .../tdc-regions-security-and-limitations.md | 94 ++++++ ai/tdc/reference/tdc-troubleshooting.md | 190 +++++++++++ ai/tdc/tdc-overview.md | 72 +++++ ai/tdc/tdc-quick-start.md | 130 ++++++++ 23 files changed, 2759 insertions(+) create mode 100644 ai/tdc/concepts/tdc-concepts-and-architecture.md create mode 100644 ai/tdc/examples/tdc-agent-sandbox-example.md create mode 100644 ai/tdc/examples/tdc-daily-workflow-example.md create mode 100644 ai/tdc/examples/tdc-git-workspace-for-agents-example.md create mode 100644 ai/tdc/examples/tdc-journal-agent-workflow-example.md create mode 100644 ai/tdc/examples/tdc-query-sql-with-roles-example.md create mode 100644 ai/tdc/examples/tdc-share-filesystem-across-machines-example.md create mode 100644 ai/tdc/examples/tdc-vault-agent-secrets-example.md create mode 100644 ai/tdc/guides/tdc-filesystem-git.md create mode 100644 ai/tdc/guides/tdc-filesystem-journal.md create mode 100644 ai/tdc/guides/tdc-filesystem-vault.md create mode 100644 ai/tdc/guides/tdc-filesystem.md create mode 100644 ai/tdc/guides/tdc-install-configure-update.md create mode 100644 ai/tdc/guides/tdc-organization.md create mode 100644 ai/tdc/guides/tdc-starter-database.md create mode 100644 ai/tdc/reference/tdc-cli-reference.md create mode 100644 ai/tdc/reference/tdc-configuration-and-credentials.md create mode 100644 ai/tdc/reference/tdc-regions-security-and-limitations.md create mode 100644 ai/tdc/reference/tdc-troubleshooting.md create mode 100644 ai/tdc/tdc-overview.md create mode 100644 ai/tdc/tdc-quick-start.md diff --git a/TOC-ai.md b/TOC-ai.md index e79d9a34cc2be..cbf1494523e9f 100644 --- a/TOC-ai.md +++ b/TOC-ai.md @@ -7,10 +7,15 @@ - [Get Started via Python](/ai/quickstart-via-python.md) - [Get Started via SQL](/ai/quickstart-via-sql.md) +- TiDB Cloud CLI (tdc) (Preview) + - [Overview](/ai/tdc/tdc-overview.md) + - [Quick Start](/ai/tdc/tdc-quick-start.md) ## CONCEPTS - [Vector Search](/ai/concepts/vector-search-overview.md) +- TiDB Cloud CLI (tdc) (Preview) + - [Concepts and Architecture](/ai/tdc/concepts/tdc-concepts-and-architecture.md) ## GUIDES @@ -30,6 +35,14 @@ - [Join Queries](/ai/guides/join-queries.md) - [Raw SQL Queries](/ai/guides/raw-queries.md) - [Transactions](/ai/guides/transactions.md) +- TiDB Cloud CLI (tdc) (Preview) + - [Install, Configure, and Update tdc](/ai/tdc/guides/tdc-install-configure-update.md) + - [Organization](/ai/tdc/guides/tdc-organization.md) + - [Starter Database](/ai/tdc/guides/tdc-starter-database.md) + - [Filesystem](/ai/tdc/guides/tdc-filesystem.md) + - [Filesystem Git](/ai/tdc/guides/tdc-filesystem-git.md) + - [Filesystem Journal](/ai/tdc/guides/tdc-filesystem-journal.md) + - [Filesystem Vault](/ai/tdc/guides/tdc-filesystem-vault.md) ## EXAMPLES @@ -44,6 +57,14 @@ - [RAG Application](/ai/examples/rag-with-pytidb.md) - [Conversational Memory](/ai/examples/memory-with-pytidb.md) - [Text-to-SQL](/ai/examples/text2sql-with-pytidb.md) +- TiDB Cloud CLI (tdc) (Preview) + - [Agent Sandbox](/ai/tdc/examples/tdc-agent-sandbox-example.md) + - [Daily Workflow](/ai/tdc/examples/tdc-daily-workflow-example.md) + - [Query SQL with Roles](/ai/tdc/examples/tdc-query-sql-with-roles-example.md) + - [Share a Filesystem Across Machines](/ai/tdc/examples/tdc-share-filesystem-across-machines-example.md) + - [Git Workspace for Agents](/ai/tdc/examples/tdc-git-workspace-for-agents-example.md) + - [Journal an Agent Workflow](/ai/tdc/examples/tdc-journal-agent-workflow-example.md) + - [Delegate Vault Secrets](/ai/tdc/examples/tdc-vault-agent-secrets-example.md) ## INTEGRATIONS @@ -84,3 +105,8 @@ - [Performance Tuning](/ai/reference/vector-search-improve-performance.md) - [Limitations](/ai/reference/vector-search-limitations.md) - [Changelogs](/ai/reference/vector-search-changelogs.md) +- TiDB Cloud CLI (tdc) (Preview) + - [CLI Reference](/ai/tdc/reference/tdc-cli-reference.md) + - [Configuration and Credentials](/ai/tdc/reference/tdc-configuration-and-credentials.md) + - [Regions, Security, and Limitations](/ai/tdc/reference/tdc-regions-security-and-limitations.md) + - [Troubleshooting](/ai/tdc/reference/tdc-troubleshooting.md) diff --git a/ai/_index.md b/ai/_index.md index bf8a92d7832e7..fbb035e71d94c 100644 --- a/ai/_index.md +++ b/ai/_index.md @@ -16,6 +16,13 @@ Get up and running quickly with TiDB's AI capabilities. | [Get Started with Python](/ai/quickstart-via-python.md) | Build your first AI application with TiDB in minutes using Python. | | [Get Started with SQL](/ai/quickstart-via-sql.md) | Quick start guide for vector search using SQL. | +### TiDB Cloud CLI (tdc) (Preview) + +| Document | Description | +| --- | --- | +| [tdc Overview](/ai/tdc/tdc-overview.md) | Understand what tdc manages and how it uses its bundled Filesystem companion. | +| [Get Started with tdc](/ai/tdc/tdc-quick-start.md) | Install and configure tdc, then complete a first database or Filesystem operation. | + ## Concepts Understand the foundational concepts behind AI-powered search in TiDB. @@ -23,6 +30,7 @@ Understand the foundational concepts behind AI-powered search in TiDB. | Document | Description | | --- | --- | | [Vector Search](/ai/concepts/vector-search-overview.md) | Comprehensive overview of vector search, including concepts, how it works, and use cases. | +| [tdc Concepts and Architecture (Preview)](/ai/tdc/concepts/tdc-concepts-and-architecture.md) | Understand profiles, regions, credentials, SQL roles, Filesystems, and the Drive9 companion boundary. | ## Guides @@ -39,6 +47,18 @@ Step-by-step guides for building AI applications with TiDB using the [`pytidb`]( | [Auto Embedding](/ai/guides/auto-embedding.md) | Automatically generate embeddings on data insertion. | | [Filtering](/ai/guides/filtering.md) | Filter search results with metadata conditions. | +### TiDB Cloud CLI (tdc) (Preview) + +| Document | Description | +| --- | --- | +| [Install, Configure, and Update tdc](/ai/tdc/guides/tdc-install-configure-update.md) | Install release binaries, configure profiles, update, and uninstall tdc. | +| [Organization](/ai/tdc/guides/tdc-organization.md) | List projects and understand virtual-project selection. | +| [Starter Database](/ai/tdc/guides/tdc-starter-database.md) | Manage clusters, branches, SQL users, connection strings, and SQL execution. | +| [Filesystem](/ai/tdc/guides/tdc-filesystem.md) | Manage resources, data, layers, packs, and FUSE or WebDAV mounts. | +| [Filesystem Git](/ai/tdc/guides/tdc-filesystem-git.md) | Clone, hydrate, and manage linked Git worktrees. | +| [Filesystem Journal](/ai/tdc/guides/tdc-filesystem-journal.md) | Record, search, and verify append-only workflow events. | +| [Filesystem Vault](/ai/tdc/guides/tdc-filesystem-vault.md) | Store secrets, delegate access, audit, inject, and mount a read-only vault. | + ## Examples Complete code examples and demos showcasing TiDB's AI capabilities. @@ -52,6 +72,18 @@ Complete code examples and demos showcasing TiDB's AI capabilities. | [Conversational Memory](/ai/examples/memory-with-pytidb.md) | Persistent memory for AI agents and chatbots. | | [Text-to-SQL](/ai/examples/text2sql-with-pytidb.md) | Convert natural language to SQL queries. | +### TiDB Cloud CLI (tdc) (Preview) + +| Document | Description | +| --- | --- | +| [Agent Sandbox](/ai/tdc/examples/tdc-agent-sandbox-example.md) | Give a clean sandbox Filesystem access without TiDB Cloud API keys. | +| [Daily Workflow](/ai/tdc/examples/tdc-daily-workflow-example.md) | Manage one Starter cluster and Filesystem in a routine operator flow. | +| [Query SQL with Roles](/ai/tdc/examples/tdc-query-sql-with-roles-example.md) | Use explicit read-only, read-write, and admin SQL roles. | +| [Share a Filesystem Across Machines](/ai/tdc/examples/tdc-share-filesystem-across-machines-example.md) | Transfer an owner token securely and verify cross-machine visibility. | +| [Git Workspace for Agents](/ai/tdc/examples/tdc-git-workspace-for-agents-example.md) | Prepare a mounted Git workspace and isolated linked worktree. | +| [Journal an Agent Workflow](/ai/tdc/examples/tdc-journal-agent-workflow-example.md) | Record structured events and verify their hash chain. | +| [Delegate Vault Secrets](/ai/tdc/examples/tdc-vault-agent-secrets-example.md) | Grant an agent temporary access to one secret field. | + ## Integrations Integrate TiDB with popular AI frameworks, embedding providers, and development tools. @@ -75,3 +107,12 @@ Technical reference documentation for TiDB's AI and vector search features. | [Vector Search Index](/ai/reference/vector-search-index.md) | Create and manage vector indexes for performance. | | [Performance Tuning](/ai/reference/vector-search-improve-performance.md) | Optimize vector search performance. | | [Limitations](/ai/reference/vector-search-limitations.md) | Current limitations and constraints. | + +### TiDB Cloud CLI (tdc) (Preview) + +| Document | Description | +| --- | --- | +| [CLI Reference](/ai/tdc/reference/tdc-cli-reference.md) | Global flags, output, queries, dry-run, help, errors, and aliases. | +| [Configuration and Credentials](/ai/tdc/reference/tdc-configuration-and-credentials.md) | Profiles, precedence, local state, credentials, mount locators, and logs. | +| [Regions, Security, and Limitations](/ai/tdc/reference/tdc-regions-security-and-limitations.md) | Placement, authentication boundaries, platforms, durability, and Preview constraints. | +| [Troubleshooting](/ai/tdc/reference/tdc-troubleshooting.md) | Diagnose authentication, quota, SQL, companion, selection, and mount failures. | diff --git a/ai/tdc/concepts/tdc-concepts-and-architecture.md b/ai/tdc/concepts/tdc-concepts-and-architecture.md new file mode 100644 index 0000000000000..eed0164f523e5 --- /dev/null +++ b/ai/tdc/concepts/tdc-concepts-and-architecture.md @@ -0,0 +1,129 @@ +--- +title: tdc Concepts and Architecture +summary: Understand tdc profiles, regions, credentials, SQL roles, Filesystem resources, local state, and the bundled Drive9 companion. +--- + +# tdc Concepts and Architecture + +This document explains the concepts needed to use tdc with TiDB Cloud Starter and TiDB Cloud Filesystem. + +> **Note:** +> +> tdc is currently in Preview. Its features and command-line interface might change without prior notice. + +## Command model + +tdc uses service nouns and explicit operation names: + +```text +tdc db create-db-cluster +tdc fs copy-file +tdc fs-git clone-git-workspace +``` + +The command tree is at most two levels. Long, descriptive command and flag names make intent explicit in logs and agent-generated commands. Commands are non-interactive except for `tdc configure`. + +Structured commands return JSON by default. Use `--output text` for a terminal-oriented representation and `--query` for a JMESPath projection. + +## Profiles and regions + +A profile is a named local namespace containing TiDB Cloud placement, a default virtual project, and credentials. The default profile is named `default`; select another with `--profile`. + +tdc represents placement with one canonical region code: + +```text +aws-us-east-1 +aws-ap-southeast-1 +ali-ap-southeast-1 +``` + +The prefix identifies the cloud provider. A global `--region` value overrides `TDC_REGION_CODE` and the profile region for one command without changing saved configuration. + +During `tdc configure`, tdc calls the organization API and requires one accessible project with `type = "tidbx_virtual"`. It stores that project ID as the default for Starter cluster creation. + +## Credential boundaries + +tdc uses separate credentials for separate security boundaries: + +| Credential | Purpose | Storage | +| --- | --- | --- | +| TiDB Cloud API public/private key | Organization, Starter control plane, Filesystem provisioning and deletion | `~/.tdc/credentials` | +| DB SQL username/password | SQL access to one Starter cluster | `~/.tdc/db_users//credentials` | +| Filesystem owner token | Filesystem data plane, mounts, Git, journal, and owner vault operations | Per-resource credentials under `~/.tdc/fs_resources/` or `TDC_FS_TOKEN` | +| Delegated vault token | Limited access to selected secret fields | `TDC_VAULT_TOKEN` or an explicit command input | + +TiDB Cloud API keys are never reused as SQL passwords or Filesystem tokens. + +## SQL roles + +`tdc db create-db-sql-users` creates or repairs three stable users for a cluster: + +- `read_only` for queries that must not modify data; +- `read_write` for normal application and agent work; +- `admin` for DDL and privilege administration. + +Role selection is explicit with `--read-only`, `--read-write`, or `--admin`. Read-write is the default when no role flag is supplied. + +## One profile, multiple Filesystems + +One profile can register multiple Filesystem resources. Each resource has an isolated config file and credential file. Select a resource in this order: + +1. `--file-system-name`; +2. `TDC_FS_FILE_SYSTEM_NAME`; +3. the profile's default Filesystem; +4. the only registered Filesystem, when exactly one exists. + +If multiple resources exist and none is selected, tdc fails instead of guessing. Use `tdc fs set-default-file-system` to choose a default. + +## Config-free sandbox access + +A clean agent sandbox does not need `tdc configure` or TiDB Cloud API keys to use an existing Filesystem. Supply: + +```bash +export TDC_FS_TOKEN="" +export TDC_REGION_CODE="aws-us-east-1" +export TDC_FS_FILE_SYSTEM_NAME="workspace" +``` + +tdc resolves these values into an in-memory profile namespace. It does not write an `[env]` profile or persist the token. + +## Local state + +All tdc-owned state is under `~/.tdc/`: + +| Path | Contents | +| --- | --- | +| `config` | Non-sensitive profile, default project, and logging settings | +| `credentials` | TiDB Cloud API keys | +| `fs_resources/` | Per-profile, per-Filesystem metadata and owner credentials | +| `db_users/` | Cluster-scoped SQL credentials | +| `mounts/` | Non-secret locators for active background mounts | +| `logs/tdc.jsonl` | Redacted local operation log | +| `bin/` | Installed `tdc` and `tdc-drive9` binaries | + +Operation logging is local and is not telemetry. Set `TDC_LOGGING=off` to disable it for one process. + +## tdc and the Drive9 companion + +tdc installs [Drive9](https://github.com/mem9-ai/drive9) as the private companion name `tdc-drive9`. + +tdc owns: + +- profile, credential, region, and Filesystem selection; +- TiDB Cloud control-plane calls; +- JSON/text output, queries, errors, and local logging; +- translation from the tdc command surface to the companion. + +The companion owns: + +- Filesystem reads, writes, metadata, links, search, and layers; +- FUSE and WebDAV mount processes, caches, drain, and unmount; +- pack/unpack, Git workspace, journal, and vault semantics. + +A background mount leaves a long-running `tdc-drive9 mount --foreground` process. `tdc fs drain-file-system` asks that process to flush pending FUSE work, and `tdc fs unmount-file-system` stops the mount. Do not terminate a machine with unflushed writes or local-only overlay data that you need to keep. + +## What's next + +- [Install, Configure, and Update tdc](/ai/tdc/guides/tdc-install-configure-update.md) +- [tdc Configuration and Credentials](/ai/tdc/reference/tdc-configuration-and-credentials.md) +- [tdc Regions, Security, and Limitations](/ai/tdc/reference/tdc-regions-security-and-limitations.md) diff --git a/ai/tdc/examples/tdc-agent-sandbox-example.md b/ai/tdc/examples/tdc-agent-sandbox-example.md new file mode 100644 index 0000000000000..9c080242a49d3 --- /dev/null +++ b/ai/tdc/examples/tdc-agent-sandbox-example.md @@ -0,0 +1,106 @@ +--- +title: Use TiDB Cloud Filesystem in an Agent Sandbox +summary: Provision a Filesystem on a trusted machine and give a clean agent sandbox config-free access without TiDB Cloud API keys. +--- + +# Use TiDB Cloud Filesystem in an Agent Sandbox + +This example provisions a Filesystem on a trusted machine, transfers the minimum environment to a clean sandbox, and uses tdc without copying `~/.tdc/`. + +> **Note:** +> +> tdc is currently in Preview. Its features and command-line interface might change without prior notice. + +## Prerequisites + +- Install and configure tdc on a trusted machine. +- Install tdc in the sandbox. The release installer includes `tdc-drive9`. +- Use a secure secret manager or encrypted sandbox input for token transfer. + +## Step 1. Provision on the trusted machine + +```bash +export TDC_FS_TOKEN="$(tdc fs create-file-system \ + --file-system-name agent-sandbox \ + --query fs_token \ + --output text)" +``` + +Record the canonical region code used by the profile, for example `aws-us-east-1`. Do not print the token. + +## Step 2. Inject the minimum sandbox environment + +Configure the sandbox secret/environment mechanism with: + +```bash +TDC_FS_TOKEN= +TDC_REGION_CODE=aws-us-east-1 +TDC_FS_FILE_SYSTEM_NAME=agent-sandbox +``` + +The sandbox does not need `TDC_PUBLIC_KEY`, `TDC_PRIVATE_KEY`, `tdc configure`, or files copied from `~/.tdc/`. + +## Step 3. Verify direct access + +In the sandbox: + +```bash +printf 'sandbox ready\n' | tdc fs copy-file \ + --from-stdin \ + --to-remote /sandbox/status.txt + +tdc fs read-file --path /sandbox/status.txt +``` + +Expected output: + +```text +sandbox ready +``` + +## Step 4. Optionally mount the Filesystem + +On Linux with FUSE: + +```bash +mkdir -p /workspace +tdc fs mount-file-system \ + --file-system-name agent-sandbox \ + --mount-path /workspace \ + --driver fuse + +cat /workspace/sandbox/status.txt +``` + +On macOS, omit `--driver fuse` to use the default WebDAV path. Use FUSE only after installing macFUSE. + +After mounting, you can use `tdc fs-git`, `tdc fs-journal`, and owner-authorized `tdc fs-vault` commands with the same FS environment. Give agents a delegated `TDC_VAULT_TOKEN` instead of the owner token when they need only selected secret fields. + +## Cleanup + +Stop writers. For FUSE: + +```bash +tdc fs drain-file-system --mount-path /workspace +tdc fs unmount-file-system --mount-path /workspace +``` + +For WebDAV, close files and run only unmount. Back on the trusted machine: + +```bash +tdc fs delete-file-system \ + --file-system-name agent-sandbox \ + --confirm-file-system-name agent-sandbox +``` + +## Security notes + +- Treat `TDC_FS_TOKEN` as an owner credential. +- Do not place it in an image, repository, command flag, or operation log. +- Deleting the sandbox does not delete the remote Filesystem. +- Draining is required before deleting a FUSE sandbox when pending writes must be durable. + +## What's next + +- [Manage TiDB Cloud Filesystem with tdc](/ai/tdc/guides/tdc-filesystem.md) +- [tdc Configuration and Credentials](/ai/tdc/reference/tdc-configuration-and-credentials.md) diff --git a/ai/tdc/examples/tdc-daily-workflow-example.md b/ai/tdc/examples/tdc-daily-workflow-example.md new file mode 100644 index 0000000000000..655177738bbc6 --- /dev/null +++ b/ai/tdc/examples/tdc-daily-workflow-example.md @@ -0,0 +1,112 @@ +--- +title: Run a Daily tdc Workflow +summary: Inspect projects, manage a Starter cluster and Filesystem, check for tdc updates, and clean up resources. +--- + +# Run a Daily tdc Workflow + +This example follows a typical operator workflow across TiDB Cloud Starter and TiDB Cloud Filesystem. + +> **Note:** +> +> tdc is currently in Preview. Its features and command-line interface might change without prior notice. + +## Prerequisites + +- Install tdc and run `tdc configure`. +- Ensure your organization has capacity for one Starter cluster and one Filesystem. + +## Step 1. Inspect the active account + +```bash +tdc organization list-projects --output text +tdc db list-db-clusters --output text +tdc fs list-file-systems --output text +``` + +## Step 2. Create a Starter cluster + +```bash +tdc db create-db-cluster \ + --db-cluster-name daily-demo \ + --db-cluster-type starter \ + --dry-run + +tdc db create-db-cluster \ + --db-cluster-name daily-demo \ + --db-cluster-type starter +``` + +Record the returned cluster ID and wait until the cluster is active: + +```bash +tdc db describe-db-cluster \ + --db-cluster-id "" \ + --output text +``` + +## Step 3. Verify SQL access + +```bash +tdc db create-db-sql-users --db-cluster-id "" +tdc db execute-sql-statement \ + --db-cluster-id "" \ + --read-only \ + --sql "SELECT CURRENT_TIMESTAMP AS checked_at" \ + --output text +``` + +## Step 4. Create and use a Filesystem + +```bash +tdc fs create-file-system \ + --file-system-name daily-workspace \ + --set-default + +printf 'daily workflow\n' | tdc fs copy-file \ + --from-stdin \ + --to-remote /notes/today.txt + +tdc fs list-files --path /notes --output text +``` + +The file in `/notes/today.txt` verifies that the selected default resource is usable. + +## Step 5. Check for updates + +Unmount active filesystems before applying an update. A check is always non-mutating: + +```bash +tdc update --check +``` + +Apply an update when appropriate: + +```bash +tdc update --dry-run +tdc update +``` + +## Cleanup + +```bash +tdc fs delete-file-system \ + --file-system-name daily-workspace \ + --confirm-file-system-name daily-workspace + +tdc db delete-db-cluster \ + --db-cluster-id "" +``` + +Deleting local tdc configuration is not a substitute for deleting remote resources. + +## Security notes + +- Do not echo FS tokens or formatted database connection strings. +- Use unique automation prefixes and delete only resources created by that run. +- Preview destructive operations with `--dry-run`. + +## What's next + +- [Manage TiDB Cloud Starter Databases](/ai/tdc/guides/tdc-starter-database.md) +- [Manage TiDB Cloud Filesystem with tdc](/ai/tdc/guides/tdc-filesystem.md) diff --git a/ai/tdc/examples/tdc-git-workspace-for-agents-example.md b/ai/tdc/examples/tdc-git-workspace-for-agents-example.md new file mode 100644 index 0000000000000..4efb162eae68c --- /dev/null +++ b/ai/tdc/examples/tdc-git-workspace-for-agents-example.md @@ -0,0 +1,83 @@ +--- +title: Prepare a Git Workspace for Agents on TiDB Cloud Filesystem +summary: Mount a Filesystem, create a fast Git workspace and linked worktree, use Git normally, and clean up safely. +--- + +# Prepare a Git Workspace for Agents on TiDB Cloud Filesystem + +This example prepares a repository and an isolated linked worktree for an agent. + +> **Note:** +> +> tdc is currently in Preview. Its features and command-line interface might change without prior notice. + +## Prerequisites + +- Select a Filesystem. +- Use Linux FUSE or macOS with macFUSE and explicit `--driver fuse`. +- Install Git and configure repository authentication. + +## Step 1. Mount a workspace + +```bash +mkdir -p /path/to/workspace +tdc fs mount-file-system \ + --mount-path /path/to/workspace \ + --driver fuse +``` + +## Step 2. Clone and hydrate + +```bash +tdc fs-git clone-git-workspace \ + --repo-url https://github.com/pingcap/tidb.git \ + --target-path /path/to/workspace/tidb \ + --blobless \ + --hydrate sync +``` + +Verify: + +```bash +git -C /path/to/workspace/tidb status +``` + +## Step 3. Create an agent worktree + +```bash +tdc fs-git add-git-worktree \ + --base-path /path/to/workspace/tidb \ + --worktree-path /path/to/workspace/tidb-agent-task \ + --branch-name agent-task +``` + +The agent can now use ordinary tools: + +```bash +git -C /path/to/workspace/tidb-agent-task status +``` + +Commit or push required changes before removing the worktree. + +## Cleanup + +```bash +tdc fs-git remove-git-worktree \ + --worktree-path /path/to/workspace/tidb-agent-task + +tdc fs drain-file-system --mount-path /path/to/workspace +tdc fs unmount-file-system --mount-path /path/to/workspace +``` + +Use `--force` for worktree removal only when uncommitted changes can be discarded. + +## Security and durability notes + +- Repository credentials are managed by Git, not tdc. +- The coding-agent profile keeps `.git` and ignored generated files locally for performance. +- Preserve or pack local overlay state before deleting an ephemeral machine when it cannot be rebuilt. + +## What's next + +- [Use Git Workspaces on TiDB Cloud Filesystem](/ai/tdc/guides/tdc-filesystem-git.md) +- [Manage TiDB Cloud Filesystem with tdc](/ai/tdc/guides/tdc-filesystem.md) diff --git a/ai/tdc/examples/tdc-journal-agent-workflow-example.md b/ai/tdc/examples/tdc-journal-agent-workflow-example.md new file mode 100644 index 0000000000000..788953e6085ca --- /dev/null +++ b/ai/tdc/examples/tdc-journal-agent-workflow-example.md @@ -0,0 +1,84 @@ +--- +title: Record an Agent Workflow in a Filesystem Journal +summary: Create a journal, append structured agent events, search the workflow, and verify the journal hash chain. +--- + +# Record an Agent Workflow in a Filesystem Journal + +This example records an agent task as structured, ordered events rather than appending unvalidated text to a mutable file. + +> **Note:** +> +> tdc is currently in Preview. Its features and command-line interface might change without prior notice. + +## Prerequisites + +Select a Filesystem through a configured profile or FS token environment. + +## Step 1. Create the journal + +```bash +tdc fs-journal create-journal \ + --journal-id jrn-agent-demo \ + --journal-kind agent \ + --title "dependency update" \ + --actor agent:dependency-bot \ + --label repository=demo \ + --label environment=test +``` + +## Step 2. Append workflow events + +```bash +tdc fs-journal append-journal-entries \ + --journal-id jrn-agent-demo \ + --idempotency-key dependency-update-start \ + --entry-json '{"type":"task.started","status":"running"}' + +tdc fs-journal append-journal-entries \ + --journal-id jrn-agent-demo \ + --entry-json '{"type":"test.finished","status":"passed","suite":"unit"}' \ + --entry-json '{"type":"task.finished","status":"completed"}' +``` + +## Step 3. Read and search + +```bash +tdc fs-journal read-journal-entries \ + --journal-id jrn-agent-demo \ + --after-seq 0 \ + --limit 100 \ + --output text + +tdc fs-journal search-journal-entries \ + --entry-type task.finished \ + --status completed \ + --label repository=demo \ + --include-entries +``` + +The ordered result should include the start, test, and completion events. + +## Step 4. Verify integrity + +```bash +tdc fs-journal verify-journal \ + --journal-id jrn-agent-demo \ + --output text +``` + +A successful result confirms the stored sequence and hash chain are consistent. + +## Cleanup + +Journals are append-only and currently have no delete command in the tdc public surface. Use a synthetic journal ID and retain it as workflow evidence. Delete the containing Filesystem only when its complete contents are no longer needed. + +## Security notes + +- Do not put API keys, passwords, SQL text containing secrets, or raw file contents in journal payloads. +- Hash-chain verification detects stored-chain inconsistency; it does not prove the original event was truthful. + +## What's next + +- [Use TiDB Cloud Filesystem Journals](/ai/tdc/guides/tdc-filesystem-journal.md) +- [Delegate Secrets to an Agent](/ai/tdc/examples/tdc-vault-agent-secrets-example.md) diff --git a/ai/tdc/examples/tdc-query-sql-with-roles-example.md b/ai/tdc/examples/tdc-query-sql-with-roles-example.md new file mode 100644 index 0000000000000..d9289fc297500 --- /dev/null +++ b/ai/tdc/examples/tdc-query-sql-with-roles-example.md @@ -0,0 +1,103 @@ +--- +title: Query TiDB Cloud Starter with Explicit SQL Roles +summary: Prepare tdc-managed SQL users and run read-only, read-write, and admin statements with clear privilege intent. +--- + +# Query TiDB Cloud Starter with Explicit SQL Roles + +This example uses all three tdc-managed SQL roles without exposing generated passwords. + +> **Note:** +> +> tdc is currently in Preview. Its features and command-line interface might change without prior notice. + +## Prerequisites + +- Configure tdc. +- Select an active Starter cluster ID. + +## Step 1. Prepare users + +```bash +tdc db create-db-sql-users \ + --db-cluster-id "" +``` + +The command is idempotent and creates or repairs `read_only`, `read_write`, and `admin` credentials. + +## Step 2. Use admin for schema changes + +```bash +tdc db execute-sql-statement \ + --db-cluster-id "" \ + --admin \ + --sql "CREATE DATABASE IF NOT EXISTS role_demo" + +tdc db execute-sql-statement \ + --db-cluster-id "" \ + --admin \ + --database role_demo \ + --sql "CREATE TABLE IF NOT EXISTS messages (id BIGINT PRIMARY KEY, body VARCHAR(255))" +``` + +## Step 3. Use read-write for data changes + +```bash +tdc db execute-sql-statement \ + --db-cluster-id "" \ + --read-write \ + --database role_demo \ + --sql "INSERT INTO messages(id, body) VALUES (1, 'hello') ON DUPLICATE KEY UPDATE body = VALUES(body)" +``` + +## Step 4. Use read-only for verification + +```bash +tdc db execute-sql-statement \ + --db-cluster-id "" \ + --read-only \ + --database role_demo \ + --sql "SELECT id, body FROM messages ORDER BY id" \ + --output text +``` + +Expected result contains ID `1` and body `hello`. + +## Step 5. Format a connection environment + +Write the output directly to a protected local file instead of displaying it: + +```bash +umask 077 +tdc db format-db-connection-string \ + --db-cluster-id "" \ + --read-only \ + --database role_demo \ + --format env \ + --env-include-database-url > .env.tidb +``` + +Do not commit `.env.tidb`. + +## Cleanup + +```bash +tdc db execute-sql-statement \ + --db-cluster-id "" \ + --admin \ + --sql "DROP DATABASE role_demo" + +rm -f .env.tidb +``` + +## Security notes + +- Use the least privileged explicit role for each statement. +- tdc accepts one SQL statement per invocation. +- HTTPS is the default transport; `--transport mysql` is an explicit fallback. +- Connection strings and environment output contain credentials. + +## What's next + +- [Manage TiDB Cloud Starter Databases](/ai/tdc/guides/tdc-starter-database.md) +- [tdc Configuration and Credentials](/ai/tdc/reference/tdc-configuration-and-credentials.md) diff --git a/ai/tdc/examples/tdc-share-filesystem-across-machines-example.md b/ai/tdc/examples/tdc-share-filesystem-across-machines-example.md new file mode 100644 index 0000000000000..32b6d301f67bf --- /dev/null +++ b/ai/tdc/examples/tdc-share-filesystem-across-machines-example.md @@ -0,0 +1,100 @@ +--- +title: Share a TiDB Cloud Filesystem Across Machines +summary: Create one Filesystem, securely access it from a second machine, and verify data-plane and mount visibility. +--- + +# Share a TiDB Cloud Filesystem Across Machines + +This example creates a Filesystem on machine A and accesses the same data from machine B without copying a tdc profile. + +> **Note:** +> +> tdc is currently in Preview. Its features and command-line interface might change without prior notice. + +## Prerequisites + +- Machine A has configured tdc. +- Both machines have tdc installed. +- You have a secure secret-transfer channel. + +## Step 1. Create the Filesystem on machine A + +```bash +export TDC_FS_TOKEN="$(tdc fs create-file-system \ + --file-system-name shared-workspace \ + --query fs_token \ + --output text)" + +printf 'from machine A\n' | tdc fs copy-file \ + --file-system-name shared-workspace \ + --from-stdin \ + --to-remote /shared/origin.txt +``` + +Transfer the token through a secret manager. Also communicate the canonical region code and Filesystem name. + +## Step 2. Configure machine B in memory + +```bash +export TDC_FS_TOKEN="" +export TDC_REGION_CODE="aws-us-east-1" +export TDC_FS_FILE_SYSTEM_NAME="shared-workspace" +``` + +No `tdc configure` is required. + +## Step 3. Verify direct visibility on machine B + +```bash +tdc fs read-file --path /shared/origin.txt +printf 'from machine B\n' | tdc fs copy-file --from-stdin --to-remote /shared/second.txt +``` + +## Step 4. Verify mount and data-plane visibility + +```bash +mkdir -p /path/to/shared-workspace +tdc fs mount-file-system \ + --file-system-name shared-workspace \ + --mount-path /path/to/shared-workspace + +cat /path/to/shared-workspace/shared/origin.txt +printf 'written through mount\n' > /path/to/shared-workspace/shared/mounted.txt +tdc fs read-file --path /shared/mounted.txt +``` + +The first read proves data-plane writes are visible through the mount. The final read proves mount writes are visible through the data plane after they are flushed. + +## Cleanup + +Stop writers. If the mount is FUSE: + +```bash +tdc fs drain-file-system --mount-path /path/to/shared-workspace +``` + +Unmount either driver: + +```bash +tdc fs unmount-file-system --mount-path /path/to/shared-workspace +unset TDC_FS_TOKEN TDC_REGION_CODE TDC_FS_FILE_SYSTEM_NAME +``` + +On machine A: + +```bash +tdc fs delete-file-system \ + --file-system-name shared-workspace \ + --confirm-file-system-name shared-workspace +``` + +## Security notes + +- The FS token grants owner access. Transfer it as a secret, not in chat or command history. +- Concurrent writers can overwrite the same paths; coordinate ownership at the workflow level. +- Do not terminate a machine before pending FUSE writes are drained. + +## What's next + +- [Manage TiDB Cloud Filesystem with tdc](/ai/tdc/guides/tdc-filesystem.md) +- [Use a Filesystem in an Agent Sandbox](/ai/tdc/examples/tdc-agent-sandbox-example.md) diff --git a/ai/tdc/examples/tdc-vault-agent-secrets-example.md b/ai/tdc/examples/tdc-vault-agent-secrets-example.md new file mode 100644 index 0000000000000..99bf88c5ab705 --- /dev/null +++ b/ai/tdc/examples/tdc-vault-agent-secrets-example.md @@ -0,0 +1,97 @@ +--- +title: Delegate Filesystem Vault Secrets to an Agent +summary: Store a secret, grant one field to an agent, inject it into a process, audit access, and revoke the grant. +--- + +# Delegate Filesystem Vault Secrets to an Agent + +This example gives an agent temporary access to one field without sharing the Filesystem owner token. + +> **Note:** +> +> tdc is currently in Preview. Its features and command-line interface might change without prior notice. + +## Prerequisites + +- Select a Filesystem with owner access. +- Store the source secret value in a protected file. + +## Step 1. Create a secret + +```bash +tdc fs-vault create-secret \ + --secret-name service-demo \ + --field ENDPOINT=https://service.example \ + --field API_TOKEN=@./api-token.txt +``` + +## Step 2. Create a narrow grant + +```bash +export TDC_VAULT_TOKEN="$(tdc fs-vault create-grant \ + --agent-id example-agent \ + --scope service-demo/ENDPOINT \ + --permission read \ + --ttl 10m \ + --label-hint example \ + --token-only)" +``` + +Record the returned grant ID from the structured create result in a real workflow. The token is captured and not printed. + +## Step 3. Use the delegated field + +```bash +tdc fs-vault read-secret \ + --secret-name service-demo \ + --field ENDPOINT \ + --format raw +``` + +Inject the allowed fields into a command: + +```bash +tdc fs-vault run-with-secret \ + --secret-path /n/vault/service-demo \ + -- sh -c 'test -n "$ENDPOINT"' +``` + +The process exits successfully when the permitted field is present. Do not use commands that print all environment values. + +## Step 4. Audit and revoke + +```bash +tdc fs-vault list-audit-events \ + --secret-name service-demo \ + --agent-id example-agent \ + --limit 20 + +tdc fs-vault delete-grant \ + --grant-id "" \ + --revoked-by operator \ + --reason task-complete +``` + +Unset the local token: + +```bash +unset TDC_VAULT_TOKEN +``` + +## Cleanup + +```bash +tdc fs-vault delete-secret --secret-name service-demo +rm -f ./api-token.txt +``` + +## Security notes + +- Scope grants to the smallest set of fields and shortest useful TTL. +- A revoked token cannot authorize new reads, but it cannot erase a value already read by a process. +- Avoid secret flags because process listings and shell history can retain them. + +## What's next + +- [Use TiDB Cloud Filesystem Vault](/ai/tdc/guides/tdc-filesystem-vault.md) +- [tdc Regions, Security, and Limitations](/ai/tdc/reference/tdc-regions-security-and-limitations.md) diff --git a/ai/tdc/guides/tdc-filesystem-git.md b/ai/tdc/guides/tdc-filesystem-git.md new file mode 100644 index 0000000000000..05d41eec7eebc --- /dev/null +++ b/ai/tdc/guides/tdc-filesystem-git.md @@ -0,0 +1,98 @@ +--- +title: Use Git Workspaces on TiDB Cloud Filesystem +summary: Clone, hydrate, and manage linked Git worktrees in a mounted TiDB Cloud Filesystem workspace. +--- + +# Use Git Workspaces on TiDB Cloud Filesystem + +`tdc fs-git` accelerates Git workspace setup on mounted TiDB Cloud Filesystem paths. It augments Git; you continue to use ordinary `git` commands for status, edit, add, commit, fetch, and push. + +> **Note:** +> +> tdc is currently in Preview. Its features and command-line interface might change without prior notice. + +## Prerequisites + +- Mount a Filesystem through FUSE. Git workspace acceleration relies on the mounted Filesystem runtime. +- Install `git` and configure any repository credentials independently. +- Ensure the FS owner token or selected profile can access the Filesystem. + +## Clone a workspace + +```bash +tdc fs-git clone-git-workspace \ + --repo-url https://github.com/pingcap/tidb.git \ + --target-path /path/to/workspace/tidb +``` + +For a large repository, create a blobless workspace and hydrate synchronously: + +```bash +tdc fs-git clone-git-workspace \ + --repo-url https://github.com/pingcap/tidb.git \ + --target-path /path/to/workspace/tidb \ + --blobless \ + --hydrate sync +``` + +`--hydrate` accepts `auto`, `background`, `sync`, or `off`. + +## Hydrate an existing workspace + +```bash +tdc fs-git hydrate-git-workspace \ + --target-path /path/to/workspace/tidb \ + --timeout 30m +``` + +Hydration materializes clean Git objects for a fast or blobless workspace. It does not discard working-tree changes. + +## Add a linked worktree + +```bash +tdc fs-git add-git-worktree \ + --base-path /path/to/workspace/tidb \ + --worktree-path /path/to/workspace/tidb-feature \ + --branch-name feature-x +``` + +Use `--detach` for a detached worktree, `--commit-ish` to select a starting revision, and `--blobless` with `--hydrate` when the base workspace uses the blobless mode. + +Use Git normally: + +```bash +git -C /path/to/workspace/tidb-feature status +git -C /path/to/workspace/tidb-feature add . +git -C /path/to/workspace/tidb-feature commit -m "Implement feature x" +``` + +## Remove a worktree + +```bash +tdc fs-git remove-git-worktree \ + --worktree-path /path/to/workspace/tidb-feature +``` + +The command refuses a dirty worktree by default. Use `--force` only after deciding that local changes can be discarded: + +```bash +tdc fs-git remove-git-worktree \ + --worktree-path /path/to/workspace/tidb-feature \ + --force +``` + +## Lifecycle guidance + +Before terminating an ephemeral machine: + +1. Commit or otherwise preserve required working-tree changes. +2. Remove linked worktrees you no longer need. +3. Drain the Filesystem mount. +4. Unmount it. + +The default coding-agent mount profile keeps `.git` and rebuildable generated files in local overlay storage. Preserve or pack that local state when it must survive machine deletion. + +## What's next + +- [Prepare a Git Workspace for Agents](/ai/tdc/examples/tdc-git-workspace-for-agents-example.md) +- [Manage TiDB Cloud Filesystem with tdc](/ai/tdc/guides/tdc-filesystem.md) diff --git a/ai/tdc/guides/tdc-filesystem-journal.md b/ai/tdc/guides/tdc-filesystem-journal.md new file mode 100644 index 0000000000000..3eb31a3053dd1 --- /dev/null +++ b/ai/tdc/guides/tdc-filesystem-journal.md @@ -0,0 +1,82 @@ +--- +title: Use TiDB Cloud Filesystem Journals +summary: Create append-only workflow journals, append and search structured events, and verify their hash chains. +--- + +# Use TiDB Cloud Filesystem Journals + +`tdc fs-journal` provides an append-only, verifiable ledger for agent and workflow events. Unlike a mutable text file, a journal assigns ordered sequence numbers, supports structured search, and maintains a hash chain that can detect alteration. + +> **Note:** +> +> tdc is currently in Preview. Its features and command-line interface might change without prior notice. + +## Prerequisites + +Select a Filesystem through a profile or provide `TDC_FS_TOKEN`, `TDC_REGION_CODE`, and `TDC_FS_FILE_SYSTEM_NAME`. + +## Create a journal + +```bash +tdc fs-journal create-journal \ + --journal-id jrn-demo \ + --journal-kind agent \ + --title "demo task" \ + --actor agent:tdc \ + --label env=dev +``` + +`--journal-id` is optional and generated when omitted. Labels are repeatable. + +## Append entries + +Append one or more JSON objects: + +```bash +tdc fs-journal append-journal-entries \ + --journal-id jrn-demo \ + --entry-json '{"type":"task.started","status":"running"}' \ + --entry-json '{"type":"tool.called","tool":"tdc"}' +``` + +Use `--entry-type` as a default for entries without `type`, and add `--source` or repeatable `--subject` metadata. `--idempotency-key` makes a retry deterministic; tdc generates one when omitted. + +For pipelines, send JSON Lines on stdin, or use `--json-array` for a JSON array. + +## Read and search + +Read entries after a sequence: + +```bash +tdc fs-journal read-journal-entries \ + --journal-id jrn-demo \ + --after-seq 0 \ + --limit 100 +``` + +Search across journals: + +```bash +tdc fs-journal search-journal-entries \ + --entry-type task.started \ + --journal-kind agent \ + --label env=dev \ + --include-entries +``` + +Search also supports status, actor, subject, `--since`, `--until`, `--limit`, and pagination cursor filters. + +## Verify integrity + +```bash +tdc fs-journal verify-journal \ + --journal-id jrn-demo \ + --output text +``` + +Verification recalculates the ordered hash chain and reports whether the entries are internally consistent. It does not assert that the event payload was truthful when originally appended. + +## What's next + +- [Record an Agent Workflow in a Journal](/ai/tdc/examples/tdc-journal-agent-workflow-example.md) +- [tdc Configuration and Credentials](/ai/tdc/reference/tdc-configuration-and-credentials.md) diff --git a/ai/tdc/guides/tdc-filesystem-vault.md b/ai/tdc/guides/tdc-filesystem-vault.md new file mode 100644 index 0000000000000..293407d189509 --- /dev/null +++ b/ai/tdc/guides/tdc-filesystem-vault.md @@ -0,0 +1,141 @@ +--- +title: Use TiDB Cloud Filesystem Vault +summary: Store Filesystem secrets, delegate limited access, inject secrets into processes, audit access, and mount a read-only vault. +--- + +# Use TiDB Cloud Filesystem Vault + +`tdc fs-vault` stores structured secrets and delegates limited, expiring access to agents. Owner operations use the Filesystem owner credential; delegated reads use a vault token scoped to selected secrets or fields. + +> **Note:** +> +> tdc is currently in Preview. Its features and command-line interface might change without prior notice. + +## Prerequisites + +Select a Filesystem through a profile or the config-free FS environment variables. Never print, log, or commit owner or delegated tokens. + +## Create and replace secrets + +Create a secret with repeatable fields: + +```bash +tdc fs-vault create-secret \ + --secret-name db-prod \ + --field DB_URL=mysql://example \ + --field PASSWORD=@./password.txt +``` + +`key=value` uses a literal value, `key=@file` reads a file, and `key=-` reads the value from stdin. + +Replace all fields with files from a directory: + +```bash +tdc fs-vault replace-secret \ + --secret-path /n/vault/db-prod \ + --from-directory ./secret-fields +``` + +## Read, list, and delete + +```bash +tdc fs-vault list-secrets +tdc fs-vault read-secret --secret-name db-prod +tdc fs-vault read-secret --secret-name db-prod --field DB_URL --format raw +tdc fs-vault read-secret --secret-name db-prod --field DB_URL --format env +``` + +Delete an owner-visible secret: + +```bash +tdc fs-vault delete-secret --secret-name db-prod +``` + +Raw and environment output contains plaintext. Direct it only to the intended process. + +## Delegate limited access + +Create a short-lived read grant and capture its token: + +```bash +export TDC_VAULT_TOKEN="$(tdc fs-vault create-grant \ + --agent-id deploy-agent \ + --scope db-prod/DB_URL \ + --permission read \ + --ttl 10m \ + --token-only)" +``` + +Scopes are repeatable. `--label-hint` can add non-secret operator context. + +Use the delegated token: + +```bash +tdc fs-vault read-secret \ + --secret-name db-prod \ + --field DB_URL \ + --format raw +``` + +`TDC_VAULT_TOKEN` is preferred over `--vault-token` because command-line values can remain in process listings or shell history. + +## Inject a secret into a process + +```bash +tdc fs-vault run-with-secret \ + --secret-path /n/vault/db-prod \ + -- env +``` + +The child receives secret fields as environment variables. Avoid commands that print the complete environment in production; `env` is shown only to demonstrate the interface. + +## Audit and revoke + +```bash +tdc fs-vault list-audit-events \ + --secret-name db-prod \ + --agent-id deploy-agent \ + --since 24h \ + --limit 20 + +tdc fs-vault delete-grant \ + --grant-id "" \ + --revoked-by operator \ + --reason rotated +``` + +Revocation prevents new authorized operations. It cannot erase secret values a process already read. + +## Mount a read-only vault + +On macOS or Linux with FUSE support: + +```bash +mkdir -p /path/to/vault +tdc fs-vault mount-vault \ + --mount-path /path/to/vault \ + --vault-token "$TDC_VAULT_TOKEN" +``` + +The mount is read-only. `--foreground` keeps it attached to the terminal, and `--ready-timeout` changes the background readiness wait. + +Unmount: + +```bash +tdc fs-vault unmount-vault --mount-path /path/to/vault +``` + +Unmount also supports `--timeout`, `--force`, and `--ignore-absent`. Vault mount is unavailable on Windows and requires FUSE support; direct `read-secret` and `run-with-secret` do not require a mount. + +## Security guidance + +- Give an agent the narrowest field scope and shortest practical TTL. +- Prefer `run-with-secret` over writing plaintext to disk. +- Do not store delegated tokens in tdc config or operation logs. +- Stop processes using a vault mount before unmounting. +- Revoke a grant after the task finishes. + +## What's next + +- [Delegate Secrets to an Agent](/ai/tdc/examples/tdc-vault-agent-secrets-example.md) +- [tdc Regions, Security, and Limitations](/ai/tdc/reference/tdc-regions-security-and-limitations.md) diff --git a/ai/tdc/guides/tdc-filesystem.md b/ai/tdc/guides/tdc-filesystem.md new file mode 100644 index 0000000000000..2a3ba4f1dd252 --- /dev/null +++ b/ai/tdc/guides/tdc-filesystem.md @@ -0,0 +1,301 @@ +--- +title: Manage TiDB Cloud Filesystem with tdc +summary: Manage Filesystem resources, operate on files, use layers and packs, and mount Filesystems through the bundled Drive9 companion. +--- + +# Manage TiDB Cloud Filesystem with tdc + +Use `tdc fs` to provision TiDB Cloud Filesystem resources and access their data from commands or local mounts. + +> **Note:** +> +> tdc is currently in Preview. Its features and command-line interface might change without prior notice. + +## Prerequisites + +- Run `tdc configure` before provisioning or deleting a Filesystem. +- Install tdc with the release installer so the `tdc-drive9` companion is next to the `tdc` binary. +- Treat the returned FS owner token as a secret. + +Data-plane commands can instead use an existing Filesystem with `TDC_FS_TOKEN`, `TDC_REGION_CODE`, and `TDC_FS_FILE_SYSTEM_NAME`, without TiDB Cloud API keys. + +## Manage Filesystem resources + +Create a resource and make it the profile default: + +```bash +tdc fs create-file-system \ + --file-system-name workspace \ + --set-default +``` + +The JSON response includes `fs_token`. Capture it without displaying the complete result: + +```bash +export TDC_FS_TOKEN="$(tdc fs create-file-system \ + --file-system-name sandbox \ + --query fs_token \ + --output text)" +``` + +List and describe locally registered resources: + +```bash +tdc fs list-file-systems +tdc fs describe-file-system --file-system-name workspace +``` + +Set or clear a profile default: + +```bash +tdc fs set-default-file-system --file-system-name workspace +tdc fs unset-default-file-system +``` + +Check the selected resource and companion: + +```bash +tdc fs check-file-system --file-system-name workspace +``` + +Delete a resource only after removing data you need: + +```bash +tdc fs delete-file-system \ + --file-system-name workspace \ + --confirm-file-system-name workspace +``` + +Create and delete support `--dry-run`. Deletion requires TiDB Cloud API keys and a locally registered resource; an FS token alone cannot delete the resource. + +## Select one of multiple Filesystems + +One profile can own multiple resources. Selection precedence is: + +1. `--file-system-name`; +2. `TDC_FS_FILE_SYSTEM_NAME`; +3. the profile default; +4. the only registered resource. + +When selection is ambiguous, tdc fails. It never chooses an arbitrary Filesystem. + +## Copy and read data + +Upload, download, and copy remotely: + +```bash +tdc fs copy-file --from-local ./README.md --to-remote /workspace/README.md +tdc fs copy-file --from-remote /workspace/README.md --to-local ./README.copy.md --create-parents +tdc fs copy-file --from-remote /workspace/README.md --to-remote /archive/README.md +``` + +Use `--overwrite` to replace an existing target, `--resume` for a supported interrupted upload or download, and `--recursive` for directories: + +```bash +tdc fs copy-file --from-local ./src --to-remote /workspace/src --recursive +tdc fs copy-file --from-local ./large.bin --to-remote /workspace/large.bin --resume +``` + +Append and stream: + +```bash +tdc fs copy-file --from-local ./tail.log --to-remote /logs/app.log --append +printf 'hello\n' | tdc fs copy-file --from-stdin --to-remote /workspace/stdin.txt +tdc fs copy-file --from-remote /workspace/stdin.txt --to-stdout +``` + +Add metadata during upload: + +```bash +tdc fs copy-file \ + --from-local ./report.md \ + --to-remote /workspace/report.md \ + --tag owner=agent \ + --tag stage=review \ + --description "agent review report" +``` + +Read a complete file or a byte range: + +```bash +tdc fs read-file --path /workspace/report.md +tdc fs read-file --path /workspace/large.bin --offset 1024 --length 4096 +``` + +## Inspect and modify the namespace + +```bash +tdc fs list-files --path /workspace +tdc fs describe-file --path /workspace/report.md +tdc fs create-directory --path /workspace/archive --mode 0755 +tdc fs move-file --from-remote /workspace/report.md --to-remote /workspace/archive/report.md +tdc fs chmod-file --path /workspace/archive/report.md --mode 0600 +tdc fs create-symlink --target archive/report.md --link-path /workspace/report.link +tdc fs create-hardlink --source-path /workspace/archive/report.md --link-path /workspace/report.hard +tdc fs delete-file --path /workspace/report.link +tdc fs delete-file --path /workspace/archive --recursive +``` + +Mutating namespace commands support `--dry-run`. + +Search content and metadata: + +```bash +tdc fs search-file-content --path /workspace --pattern "TODO" --limit 50 +tdc fs find-files --path /workspace --file-name-pattern "*.md" --tag stage=review +``` + +`find-files` also supports resource type, time, size, and result-limit filters. Both search commands accept `--layer-id`. + +## Use layers and checkpoints + +A layer records changes over a base root before you commit or discard them: + +```bash +tdc fs create-layer \ + --base-root-path /workspace \ + --layer-name agent-task \ + --durability-mode restore-safe \ + --tag task=review +``` + +Use the returned layer ID: + +```bash +tdc fs copy-file \ + --from-local ./proposal.md \ + --to-remote /workspace/proposal.md \ + --layer-id "" + +tdc fs list-layers +tdc fs describe-layer --layer-id "" +tdc fs diff-layer --layer-id "" +tdc fs create-layer-checkpoint \ + --layer-id "" \ + --checkpoint-id before-review \ + --label "before review" +``` + +Finish the layer by rolling it back or committing it: + +```bash +tdc fs rollback-layer --layer-id "" +tdc fs commit-layer --layer-id "" +``` + +These two commands represent alternative outcomes for the same work; do not run both in sequence in a real workflow. + +## Pack local overlay state + +FUSE mount profiles can route selected paths to local overlay storage. Pack those paths to a remote archive before moving to another machine: + +```bash +tdc fs pack-file-system --mount-path /path/to/workspace +tdc fs unpack-file-system --mount-path /path/to/workspace +``` + +Without an active mount, provide `--local-root`, `--remote-root`, and `--mount-profile`. `--archive-path` selects the remote archive, repeatable `--path` limits pack contents, and `--no-replace` makes unpack merge rather than replace manifest paths. + +## Mount a Filesystem + +Create the local mount path and mount in the background: + +```bash +mkdir -p /path/to/workspace +tdc fs mount-file-system \ + --file-system-name workspace \ + --mount-path /path/to/workspace +``` + +The default `--driver auto` is platform-specific. `--remote-path` exposes a subtree, `--read-only` prevents writes, and `--foreground` keeps the runtime attached to the terminal. + +### Platform behavior + +| Platform | `--driver auto` | Optional or required dependency | Notes | +| --- | --- | --- | --- | +| macOS | WebDAV | No extra dependency for WebDAV | Install macFUSE and select `--driver fuse` for the complete FUSE experience | +| Linux | FUSE | FUSE3 and access to `/dev/fuse`; install `davfs2` for explicit WebDAV | FUSE supports drain and FUSE cache controls | +| Windows | WebDAV | Windows WebClient service | Mount path must be a drive letter such as `X:`; FUSE and vault mount are unavailable | + +macOS intentionally keeps WebDAV as the automatic choice even when macFUSE is installed. To use FUSE, install a supported release from the [official macFUSE site](https://macfuse.github.io/), complete any approval or restart requested by its installer, and run: + +```bash +tdc fs mount-file-system \ + --file-system-name workspace \ + --mount-path /path/to/workspace \ + --driver fuse +``` + +Explicit FUSE supports cache controls: + +```bash +tdc fs mount-file-system \ + --file-system-name workspace \ + --mount-path /path/to/workspace \ + --driver fuse \ + --cache-dir "$HOME/.tdc/cache/workspace" \ + --read-cache-size-mb 256 \ + --read-cache-max-file-mb 16 \ + --read-cache-ttl 30s +``` + +The default mount profile is `coding-agent`, which keeps common development state such as dependencies, caches, generated output, and Git internals in a local overlay. Those local-only files do not survive machine deletion unless you pack or preserve the local volume. Use `--mount-profile portable` when you want automatic portable pack behavior, or `none` when you do not want the coding-agent overlay policy. + +## Drain and unmount + +Stop writers and close open files before cleanup. For FUSE: + +```bash +tdc fs drain-file-system \ + --mount-path /path/to/workspace \ + --timeout 30s + +tdc fs unmount-file-system \ + --mount-path /path/to/workspace +``` + +Drain waits for dirty handles and pending writes. It is not supported for WebDAV. `unmount-file-system` also supports `--timeout`, `--force`, `--ignore-absent`, `--pack-archive-path`, and `--no-auto-pack`. + +A successful background mount writes a non-secret locator under `~/.tdc/mounts/`. Drain and unmount can use that locator from the same `HOME` without `TDC_FS_TOKEN` or `TDC_REGION_CODE`. + +> **Warning:** +> +> Do not terminate a sandbox or virtual machine while writes remain pending. Remote-committed data survives, but in-memory writes, write-back data on a deleted local disk, and coding-agent local-only files can be lost. + +## Unix-style aliases + +Aliases change only the command name. All flags remain long and identical to the canonical command. + +| Alias | Canonical command | +| --- | --- | +| `tdc fs cp` | `tdc fs copy-file` | +| `tdc fs cat` | `tdc fs read-file` | +| `tdc fs ls` | `tdc fs list-files` | +| `tdc fs stat` | `tdc fs describe-file` | +| `tdc fs mv` | `tdc fs move-file` | +| `tdc fs rm` | `tdc fs delete-file` | +| `tdc fs mkdir` | `tdc fs create-directory` | +| `tdc fs chmod` | `tdc fs chmod-file` | +| `tdc fs symlink` | `tdc fs create-symlink` | +| `tdc fs hardlink` | `tdc fs create-hardlink` | +| `tdc fs grep` | `tdc fs search-file-content` | +| `tdc fs find` | `tdc fs find-files` | +| `tdc fs mount` | `tdc fs mount-file-system` | +| `tdc fs drain` | `tdc fs drain-file-system` | +| `tdc fs umount` | `tdc fs unmount-file-system` | + +## Command summary + +| Area | Commands | +| --- | --- | +| Resources | `create-file-system`, `list-file-systems`, `describe-file-system`, `set-default-file-system`, `unset-default-file-system`, `check-file-system`, `delete-file-system` | +| Data | `copy-file`, `read-file`, `list-files`, `describe-file`, `move-file`, `delete-file`, `create-directory`, `chmod-file`, `create-symlink`, `create-hardlink`, `search-file-content`, `find-files` | +| Layers | `create-layer`, `list-layers`, `describe-layer`, `diff-layer`, `create-layer-checkpoint`, `rollback-layer`, `commit-layer` | +| Portability | `pack-file-system`, `unpack-file-system` | +| Mounts | `mount-file-system`, `drain-file-system`, `unmount-file-system` | + +## What's next + +- [Use a Filesystem in an Agent Sandbox](/ai/tdc/examples/tdc-agent-sandbox-example.md) +- [Share a Filesystem Across Machines](/ai/tdc/examples/tdc-share-filesystem-across-machines-example.md) +- [Use Git Workspaces on TiDB Cloud Filesystem](/ai/tdc/guides/tdc-filesystem-git.md) diff --git a/ai/tdc/guides/tdc-install-configure-update.md b/ai/tdc/guides/tdc-install-configure-update.md new file mode 100644 index 0000000000000..c0b2166b824ff --- /dev/null +++ b/ai/tdc/guides/tdc-install-configure-update.md @@ -0,0 +1,148 @@ +--- +title: Install, Configure, and Update tdc +summary: Install tdc release binaries, configure profiles interactively or in automation, update safely, and remove the CLI. +--- + +# Install, Configure, and Update tdc + +This guide covers the supported release installers, profile configuration, help and version behavior, updates, and uninstallation. + +> **Note:** +> +> tdc is currently in Preview. Its features and command-line interface might change without prior notice. + +## Install tdc + +### macOS and Linux + +```bash +curl -fsSL https://github.com/tidbcloud/tdc/releases/latest/download/install.sh | sh -s -- --yes +export PATH="$HOME/.tdc/bin:$PATH" +tdc --version +``` + +The installer places `tdc` and its `tdc-drive9` companion in `~/.tdc/bin`. Add the `PATH` export to your shell profile. The installer does not require `sudo` and does not write credentials. + +### Windows + +```powershell +$script = "$env:TEMP\install-tdc.ps1" +iwr https://github.com/tidbcloud/tdc/releases/latest/download/install.ps1 -OutFile $script +powershell -ExecutionPolicy Bypass -File $script -Yes +$env:Path = "$HOME\.tdc\bin;$env:Path" +tdc --version +``` + +Add `$HOME\.tdc\bin` to your user `PATH` to keep tdc available in new PowerShell sessions. + +## Configure a profile + +Interactive configuration is the only tdc workflow that prompts: + +```bash +tdc configure +``` + +tdc requests a TiDB Cloud API public key, private key, and canonical region code. It validates the key by listing projects and records the unique `tidbx_virtual` project as the profile's default project. + +Configure a named profile: + +```bash +tdc configure --profile staging +``` + +For CI or another non-interactive environment, prefer environment variables: + +```bash +TDC_PUBLIC_KEY="" \ +TDC_PRIVATE_KEY="" \ +TDC_REGION_CODE="aws-us-east-1" \ +tdc configure --profile ci --non-interactive +``` + +You can also provide `--tdc-public-key`, `--tdc-private-key`, and `--region-code`, but secret flags can remain in shell history or process listings. + +Configuration precedence is command flag, environment variable, then saved profile. The global `--region` overrides only the placement for the current command: + +```bash +tdc db list-db-clusters --profile staging --region aws-us-west-2 +``` + +## Get help and version information + +All command levels support `help`, `--help`, and `--version`: + +```bash +tdc help +tdc fs help +tdc db create-db-cluster help +tdc --version +tdc fs --version +``` + +Required flags appear before optional flags in generated usage. tdc supports long flags only. + +## Update tdc + +Check without changing files: + +```bash +tdc update --check +``` + +In automation, fail when an update exists: + +```bash +tdc update --check --fail-if-update-available +``` + +Preview and apply an update: + +```bash +tdc update --dry-run +tdc update +``` + +Install a specific tdc release: + +```bash +tdc update --target-version v0.1.2 +``` + +The update command replaces both binaries in the user-owned install directory. An active Filesystem mount keeps running the already loaded companion process. To avoid mixing the old mount runtime with new CLI commands, stop writers, drain FUSE mounts, and unmount before updating: + +```bash +tdc fs drain-file-system --mount-path /path/to/workspace +tdc fs unmount-file-system --mount-path /path/to/workspace +tdc update +``` + +For WebDAV, close writers and unmount; drain is FUSE-only. Installations in protected or package-manager-owned locations are not modified. Run the installer once to migrate an older `/usr/local/bin` installation to `~/.tdc/bin`. + +## Uninstall tdc + +Remove only the binaries: + +```bash +rm -f "$HOME/.tdc/bin/tdc" "$HOME/.tdc/bin/tdc-drive9" +``` + +On Windows: + +```powershell +Remove-Item "$HOME\.tdc\bin\tdc.exe", "$HOME\.tdc\bin\tdc-drive9.exe" +``` + +Removing binaries preserves profiles, credentials, Filesystem registrations, DB SQL credentials, logs, and mount locators. Remove `~/.tdc/` only when you intend to delete all local tdc state: + +```bash +rm -rf "$HOME/.tdc" +``` + +Deleting local state does not delete remote Starter clusters or Filesystem resources. + +## What's next + +- [tdc Configuration and Credentials](/ai/tdc/reference/tdc-configuration-and-credentials.md) +- [Manage TiDB Cloud Starter Databases](/ai/tdc/guides/tdc-starter-database.md) +- [Manage TiDB Cloud Filesystem](/ai/tdc/guides/tdc-filesystem.md) diff --git a/ai/tdc/guides/tdc-organization.md b/ai/tdc/guides/tdc-organization.md new file mode 100644 index 0000000000000..fc0a923afd974 --- /dev/null +++ b/ai/tdc/guides/tdc-organization.md @@ -0,0 +1,65 @@ +--- +title: Manage TiDB Cloud Organizations with tdc +summary: List accessible TiDB Cloud projects and understand regular and virtual project types used by tdc. +--- + +# Manage TiDB Cloud Organizations with tdc + +Use `tdc organization` to inspect the projects accessible to the configured TiDB Cloud API key. + +> **Note:** +> +> tdc is currently in Preview. Its features and command-line interface might change without prior notice. + +## Prerequisites + +Run `tdc configure` with a TiDB Cloud API key that can list organization projects. + +## List projects + +```bash +tdc organization list-projects +``` + +The JSON response includes project IDs, names, and `type` values: + +- `tidbx` identifies a regular project; +- `tidbx_virtual` identifies a virtual project used as the default Starter project. + +Request a page size or continue with a returned page token: + +```bash +tdc organization list-projects --page-size 50 +tdc organization list-projects --page-size 50 --page-token "" +``` + +Render a terminal-oriented table or select fields: + +```bash +tdc organization list-projects --output text +tdc organization list-projects --query 'projects[].{id:id,name:name,type:type}' +``` + +## Default virtual project + +`tdc configure` calls the same project-listing API. Configuration succeeds only when it finds exactly one accessible `tidbx_virtual` project, and saves its ID in the selected profile: + +```toml +[default] +region_code = "aws-us-east-1" +project_id = "..." +``` + +`tdc db create-db-cluster` uses this project when `--project-id` is omitted. Pass an explicit project ID to override it for one cluster: + +```bash +tdc db create-db-cluster \ + --db-cluster-name project-specific-cluster \ + --db-cluster-type starter \ + --project-id "" +``` + +## What's next + +- [Manage TiDB Cloud Starter Databases](/ai/tdc/guides/tdc-starter-database.md) +- [tdc Configuration and Credentials](/ai/tdc/reference/tdc-configuration-and-credentials.md) diff --git a/ai/tdc/guides/tdc-starter-database.md b/ai/tdc/guides/tdc-starter-database.md new file mode 100644 index 0000000000000..9fd2eb2d8291c --- /dev/null +++ b/ai/tdc/guides/tdc-starter-database.md @@ -0,0 +1,204 @@ +--- +title: Manage TiDB Cloud Starter Databases with tdc +summary: Manage Starter clusters and branches, create SQL users, format connection strings, and execute SQL with explicit roles. +--- + +# Manage TiDB Cloud Starter Databases with tdc + +Use `tdc db` to manage TiDB Cloud Starter clusters, branches, and SQL access. + +> **Note:** +> +> tdc is currently in Preview. Its features and command-line interface might change without prior notice. + +## Prerequisites + +- Configure tdc with `tdc configure`. +- Ensure the API key can manage Starter clusters in the selected project. +- Use synthetic names in automation so cleanup can identify only resources created by that run. + +## Manage clusters + +Preview and create a Starter cluster: + +```bash +tdc db create-db-cluster \ + --db-cluster-name demo-cluster \ + --db-cluster-type starter \ + --dry-run + +tdc db create-db-cluster \ + --db-cluster-name demo-cluster \ + --db-cluster-type starter +``` + +The configured virtual project is used unless you provide `--project-id`. `--monthly-spending-limit-usd-cents` is optional; setting it can require a payment method. + +List and filter clusters: + +```bash +tdc db list-db-clusters +tdc db list-db-clusters --page-size 20 --order-by "createTime desc" +tdc db list-db-clusters --query 'clusters[].{id:id,name:display_name,state:state}' +``` + +The list command also accepts `--page-token`, `--filter`, and `--skip`. + +Describe and update a cluster: + +```bash +tdc db describe-db-cluster \ + --db-cluster-id "" \ + --view FULL + +tdc db update-db-cluster \ + --db-cluster-id "" \ + --db-cluster-name demo-cluster-renamed +``` + +An update must include a new name or spending limit. Preview mutating commands with `--dry-run`. + +Delete a cluster: + +```bash +tdc db delete-db-cluster \ + --db-cluster-id "" \ + --dry-run + +tdc db delete-db-cluster \ + --db-cluster-id "" +``` + +tdc resolves the cluster name internally; no name-confirmation flag is required. + +## Manage branches + +Create and list branches: + +```bash +tdc db create-db-cluster-branch \ + --db-cluster-id "" \ + --db-cluster-branch-name development + +tdc db list-db-cluster-branches \ + --db-cluster-id "" \ + --page-size 20 +``` + +Use `--page-token` to continue a paginated branch list. + +Describe and delete a branch: + +```bash +tdc db describe-db-cluster-branch \ + --db-cluster-id "" \ + --db-cluster-branch-id "" \ + --view FULL + +tdc db delete-db-cluster-branch \ + --db-cluster-id "" \ + --db-cluster-branch-id "" +``` + +Create and delete support `--dry-run`. + +## Create SQL users + +Create or repair the three tdc-managed SQL roles: + +```bash +tdc db create-db-sql-users \ + --db-cluster-id "" +``` + +The operation is idempotent. It reuses stable role names and stores generated credentials under `~/.tdc/db_users//credentials`. It creates: + +- `read_only`; +- `read_write`; +- `admin`. + +Preview the operation without changing users: + +```bash +tdc db create-db-sql-users \ + --db-cluster-id "" \ + --dry-run +``` + +## Format connection strings + +Read-write is the default, but explicit role selection is recommended: + +```bash +tdc db format-db-connection-string \ + --db-cluster-id "" \ + --read-write \ + --database app \ + --format mysql-uri + +tdc db format-db-connection-string \ + --db-cluster-id "" \ + --read-only \ + --format env \ + --env-prefix TIDB_ + +tdc db format-db-connection-string \ + --db-cluster-id "" \ + --admin \ + --format jdbc +``` + +Supported formats are `mysql-uri`, `jdbc`, `go-sql-driver`, `sqlalchemy`, and `env`. With `env`, `--env-include-database-url` adds a URL variable and `--env-database-url-name` changes its name. + +> **Warning:** +> +> Connection strings contain credentials. Do not write them to logs, tickets, or source control. + +## Execute SQL + +Each invocation accepts exactly one SQL statement. Use an explicit role: + +```bash +tdc db execute-sql-statement \ + --db-cluster-id "" \ + --read-only \ + --database app \ + --sql "SELECT COUNT(*) AS row_count FROM messages" \ + --output text + +tdc db execute-sql-statement \ + --db-cluster-id "" \ + --read-write \ + --database app \ + --sql "INSERT INTO messages(id, body) VALUES (1, 'hello')" + +tdc db execute-sql-statement \ + --db-cluster-id "" \ + --admin \ + --sql "CREATE DATABASE IF NOT EXISTS app" +``` + +The default `--transport https` sends the SQL request over HTTPS without a persistent database connection. Use `--transport mysql` as an explicit compatibility fallback; it opens a connection for the command and closes it afterward. + +## Command summary + +| Command | Purpose | +| --- | --- | +| `create-db-cluster` | Create a Starter cluster | +| `list-db-clusters` | List Starter clusters | +| `describe-db-cluster` | Read one cluster | +| `update-db-cluster` | Change cluster name or spending limit | +| `delete-db-cluster` | Delete a cluster | +| `create-db-cluster-branch` | Create a branch | +| `list-db-cluster-branches` | List branches | +| `describe-db-cluster-branch` | Read one branch | +| `delete-db-cluster-branch` | Delete a branch | +| `create-db-sql-users` | Create or repair three SQL roles | +| `format-db-connection-string` | Format prepared credentials | +| `execute-sql-statement` | Execute one SQL statement | + +## What's next + +- [Query SQL with Explicit Roles](/ai/tdc/examples/tdc-query-sql-with-roles-example.md) +- [tdc CLI Reference](/ai/tdc/reference/tdc-cli-reference.md) +- [Troubleshoot tdc](/ai/tdc/reference/tdc-troubleshooting.md) diff --git a/ai/tdc/reference/tdc-cli-reference.md b/ai/tdc/reference/tdc-cli-reference.md new file mode 100644 index 0000000000000..cebe12aeb9059 --- /dev/null +++ b/ai/tdc/reference/tdc-cli-reference.md @@ -0,0 +1,158 @@ +--- +title: tdc CLI Reference +summary: Reference global flags, output and query behavior, dry-run rules, help forms, errors, command families, and Filesystem aliases. +--- + +# tdc CLI Reference + +This reference describes behavior shared across the tdc command surface. + +> **Note:** +> +> tdc is currently in Preview. Its features and command-line interface might change without prior notice. + +## Syntax + +```text +tdc [subcommand] [required flags] [optional flags] [global flags] +``` + +tdc accepts long flags only. A one-letter flag such as `-p` is rejected. + +Required flags appear before optional flags in generated usage. Optional flags are enclosed in brackets: + +```text +tdc db describe-db-cluster + --db-cluster-id + [--output ] + [--view ] +``` + +## Global flags + +| Flag | Description | +| --- | --- | +| `--profile ` | Select a local profile; defaults to `default` | +| `--region ` | Override canonical placement for this command | +| `--output ` | Render `json` or `text`; default is `json` | +| `--query ` | Apply a JMESPath expression before rendering | +| `--debug` | Print redacted debug diagnostics | +| `--help` | Display help | +| `--version` | Display tdc version information | + +## Output + +Structured control-plane commands return JSON by default: + +```bash +tdc db list-db-clusters +``` + +Use text output for terminal inspection: + +```bash +tdc db list-db-clusters --output text +``` + +Raw byte-oriented commands such as `tdc fs read-file` and `tdc fs copy-file --to-stdout` write file content directly. + +## JMESPath queries + +`--query` runs after successful command execution and before output rendering: + +```bash +tdc db list-db-clusters \ + --query 'clusters[].{id:id,name:display_name,state:state}' + +tdc organization list-projects \ + --query 'projects[?type == `tidbx_virtual`].id' \ + --output text +``` + +An invalid expression fails without replacing the command result with partial output. + +## Dry-run + +Mutating control-plane commands declare `--dry-run`. The command validates local flags, profile, credentials, region, and request shape, then reports a plan without making the remote mutation. + +```bash +tdc db delete-db-cluster \ + --db-cluster-id "" \ + --dry-run +``` + +Read-only commands reject `--dry-run`. Dry-run is not a general global simulation flag and is available only where shown in command help. + +## Help and version forms + +```bash +tdc help +tdc db help +tdc db create-db-cluster help +tdc --help +tdc db --help +tdc db create-db-cluster --help +tdc --version +tdc fs --version +``` + +`help` is a command for navigating the command tree. `--help` is the conventional flag on each command; both intentionally coexist. + +## Errors and exit behavior + +Human-readable errors use a stable prefix: + +```text +tdc [ERROR]: +``` + +Errors are written to stderr and successful command output is written to stdout. Usage and configuration failures return a nonzero exit code before remote mutation. Runtime and remote API failures also return nonzero. An interrupted interactive configuration returns exit code `130`. + +`--debug` can show redacted request and resolution context. It must not show API keys, FS tokens, DB passwords, SQL text, file contents, or connection strings. + +## Command families + +| Command | Purpose | +| --- | --- | +| `tdc configure` | Configure a local profile | +| `tdc update` | Check or apply release updates | +| `tdc organization` | Inspect projects | +| `tdc db` | Manage Starter clusters, branches, and SQL | +| `tdc fs` | Manage Filesystems, files, layers, packs, and mounts | +| `tdc fs-git` | Manage Git workspaces on mounted Filesystems | +| `tdc fs-journal` | Manage verifiable journals | +| `tdc fs-vault` | Manage secrets and delegated access | + +For complete commands and flags, run: + +```bash +tdc help +tdc help +``` + +## Filesystem alias mapping + +| Alias | Canonical command | +| --- | --- | +| `cp` | `copy-file` | +| `cat` | `read-file` | +| `ls` | `list-files` | +| `stat` | `describe-file` | +| `mv` | `move-file` | +| `rm` | `delete-file` | +| `mkdir` | `create-directory` | +| `chmod` | `chmod-file` | +| `symlink` | `create-symlink` | +| `hardlink` | `create-hardlink` | +| `grep` | `search-file-content` | +| `find` | `find-files` | +| `mount` | `mount-file-system` | +| `drain` | `drain-file-system` | +| `umount` | `unmount-file-system` | + +Aliases use the same long flags, authentication, output, query, and error behavior as canonical commands. + +## Related documentation + +- [Install, Configure, and Update tdc](/ai/tdc/guides/tdc-install-configure-update.md) +- [tdc Configuration and Credentials](/ai/tdc/reference/tdc-configuration-and-credentials.md) diff --git a/ai/tdc/reference/tdc-configuration-and-credentials.md b/ai/tdc/reference/tdc-configuration-and-credentials.md new file mode 100644 index 0000000000000..2fa41a2768b8f --- /dev/null +++ b/ai/tdc/reference/tdc-configuration-and-credentials.md @@ -0,0 +1,195 @@ +--- +title: tdc Configuration and Credentials +summary: Reference tdc profiles, environment and flag precedence, local state paths, Filesystem registry, SQL credentials, mount locators, and operation logs. +--- + +# tdc Configuration and Credentials + +tdc stores all product-owned local state under `~/.tdc/` and separates non-sensitive configuration from credentials. + +> **Note:** +> +> tdc is currently in Preview. Its features and command-line interface might change without prior notice. + +## Main files + +```toml +# ~/.tdc/config +[default] +region_code = "aws-us-east-1" +project_id = "..." +fs_default_file_system_name = "workspace" + +[logging] +enabled = true +max_file_mb = 10 +max_files = 5 +``` + +```toml +# ~/.tdc/credentials +[default] +tdc_public_key = "..." +tdc_private_key = "..." +``` + +The credentials file uses owner-only permissions where the platform supports POSIX modes. + +## Profile selection + +The profile namespace is selected in this order: + +1. explicit `--profile`; +2. `TDC_PROFILE`; +3. `default`. + +An explicit empty profile is invalid. Environment credentials do not create an `[env]` profile and do not change the selected namespace. + +## TiDB Cloud API credentials + +Credential selection is: + +1. `TDC_PUBLIC_KEY` and `TDC_PRIVATE_KEY`, when either is set; +2. the selected section of `~/.tdc/credentials`. + +Both environment values are required together. tdc never mixes one environment half with one file half. + +Placement selection is: + +1. explicit global `--region`; +2. `TDC_REGION_CODE`; +3. profile `region_code`. + +Command flags, environment inputs, saved configuration, and command defaults are resolved per field. Values can therefore come from different levels when they do not form an atomic pair such as the API key pair. + +## Default Starter project + +Starter create selects a project in this order: + +1. explicit non-empty `--project-id`; +2. profile `project_id` discovered by `tdc configure`; +3. fail before sending the create request. + +Other DB commands identify resources by cluster or branch ID and do not use `project_id`. Filesystem commands do not consume the DB project default. + +## Filesystem resource registry + +One profile can register multiple Filesystems. The main config stores only the optional default name. Resource state is isolated: + +```text +~/.tdc/fs_resources///config +~/.tdc/fs_resources///credentials +``` + +The resource config contains the stored Filesystem name, tenant ID, cloud provider, region code, and creation time. The credentials file contains only the owner `api_key` and uses owner-only permissions. + +Resource selection is: + +1. explicit `--file-system-name`; +2. `TDC_FS_FILE_SYSTEM_NAME`; +3. profile `fs_default_file_system_name`; +4. the only registered resource; +5. fail as missing or ambiguous. + +FS owner credential selection for remote `fs`, `fs-git`, `fs-journal`, and owner `fs-vault` operations is: + +1. explicit `--fs-token`; +2. `TDC_FS_TOKEN`; +3. selected resource credential. + +Prefer `TDC_FS_TOKEN` over a flag because flags can remain in shell history or process listings. + +## Config-free Filesystem inputs + +A clean sandbox can use: + +```bash +export TDC_FS_TOKEN="" +export TDC_REGION_CODE="aws-us-east-1" +export TDC_FS_FILE_SYSTEM_NAME="workspace" +``` + +These values form an in-memory namespace only. tdc does not write them to `~/.tdc/`. Provisioning and deletion still require TiDB Cloud API credentials; deletion also requires the local resource registration. + +## DB SQL credentials + +Generated SQL credentials are cluster-scoped: + +```text +~/.tdc/db_users//credentials +``` + +```toml +[read_only] +username = "..." +password = "..." + +[read_write] +username = "..." +password = "..." + +[admin] +username = "..." +password = "..." +``` + +`tdc db create-db-sql-users` creates or repairs these stable users. They are not stored in the main credentials file. + +## Companion state and mount locators + +Each registered Filesystem has an isolated companion home: + +```text +~/.tdc/drive9-home/// +``` + +Do not edit this state or a standalone `~/.drive9` configuration for tdc workflows. + +A successful background FS or vault mount writes a non-secret locator: + +```text +~/.tdc/mounts/.locator.json +``` + +The locator records enough placement and companion-home information for drain and unmount from the same `HOME`. It does not contain the FS token. Successful unmount removes it. + +## Operation logs + +tdc writes redacted local JSON Lines events to: + +```text +~/.tdc/logs/tdc.jsonl +``` + +This log is local audit/debug data, not telemetry. It can include command names, flag names, profile and region, duration, exit and stable error codes, HTTP method/status, operation, and request ID. It excludes flag values, SQL, file paths and contents, payloads, connection strings, and credentials. + +Disable it for one process: + +```bash +TDC_LOGGING=off tdc db list-db-clusters +``` + +Or configure: + +```toml +[logging] +enabled = false +``` + +Environment values `off`, `false`, `0`, and `no` disable logging; `on`, `true`, `1`, and `yes` enable it. Environment takes precedence over config. + +## Sensitive values + +Treat these as secrets: + +- TiDB Cloud API private key and public-key pair; +- FS owner token; +- DB SQL usernames, passwords, and connection strings; +- delegated vault tokens and secret values. + +Do not put them in source control, tickets, logs, command examples, or unprotected shell history. + +## Related documentation + +- [tdc Regions, Security, and Limitations](/ai/tdc/reference/tdc-regions-security-and-limitations.md) +- [Troubleshoot tdc](/ai/tdc/reference/tdc-troubleshooting.md) diff --git a/ai/tdc/reference/tdc-regions-security-and-limitations.md b/ai/tdc/reference/tdc-regions-security-and-limitations.md new file mode 100644 index 0000000000000..1166cf4d2502d --- /dev/null +++ b/ai/tdc/reference/tdc-regions-security-and-limitations.md @@ -0,0 +1,94 @@ +--- +title: tdc Regions, Security, and Limitations +summary: Reference supported regions, authentication boundaries, platform dependencies, Preview constraints, and Filesystem companion behavior. +--- + +# tdc Regions, Security, and Limitations + +This reference describes current placement, authentication, platform, and Preview boundaries. + +> **Note:** +> +> tdc is currently in Preview. Its features and command-line interface might change without prior notice. + +## TiDB Cloud regions + +tdc accepts one canonical region code: + +| Canonical code | Provider | Location | +| --- | --- | --- | +| `aws-us-east-1` | AWS | N. Virginia | +| `aws-us-west-2` | AWS | Oregon | +| `aws-eu-central-1` | AWS | Frankfurt | +| `aws-ap-northeast-1` | AWS | Tokyo | +| `aws-ap-southeast-1` | AWS | Singapore | +| `ali-ap-southeast-1` | Alibaba Cloud | Singapore | + +Alibaba Cloud currently supports only Singapore in tdc. Users cannot configure raw service URLs. + +## Filesystem regions + +Filesystem endpoint availability is resolved from the hosted Drive9 region manifest. At publication time, TiDB Cloud native Filesystem mode is available for: + +- `aws-us-east-1`; +- `aws-ap-southeast-1`. + +The hosted manifest is authoritative and can change during Preview. A profile in another TiDB Cloud region can manage Starter databases but receives an unsupported Filesystem endpoint error until that placement appears in the manifest. + +## Credential requirements + +| Operation | Required credential | +| --- | --- | +| `tdc configure`, `tdc organization`, all `tdc db` control-plane operations | TiDB Cloud API public/private key | +| `tdc fs create-file-system` | TiDB Cloud API key | +| `tdc fs delete-file-system` | TiDB Cloud API key, local resource registration, and owner resource credential | +| Remote file, layer, pack, mount, Git, journal, and owner vault operations | FS owner token or registered resource credential | +| Delegated vault read, list, run, or mount | Scope-appropriate delegated vault token | +| Drain and unmount after a successful background mount | Non-secret mount locator in the same `HOME` | + +TiDB Cloud API calls use Digest authentication. SQL HTTPS execution uses generated SQL username/password Basic authentication over TLS. These credentials are not interchangeable. + +## Security guidance + +- Prefer environment variables or protected credential files for secrets. +- Use explicit read-only, read-write, or admin roles for SQL. +- Give agents delegated vault grants instead of FS owner tokens when only secret access is required. +- Use `--dry-run` before destructive control-plane operations. +- Keep `~/.tdc/credentials`, resource credentials, and DB SQL credentials owner-readable only. +- Review local operation logs before sharing diagnostics even though tdc redacts known secret classes. + +## Mount platform limitations + +| Platform | Default | Limitations | +| --- | --- | --- | +| macOS | WebDAV | Install macFUSE and explicitly use `--driver fuse` for FUSE caches, drain, and complete POSIX-oriented behavior | +| Linux | FUSE | Requires FUSE3 and `/dev/fuse`; explicit WebDAV requires `davfs2` | +| Windows | WebDAV | Requires the WebClient service and a drive-letter mount path; FUSE and vault mount are unavailable | + +FUSE and WebDAV are implemented by the bundled [Drive9](https://github.com/mem9-ai/drive9) companion. tdc does not fall back to a separate native mount implementation. + +## Durability limitations + +- Default FUSE behavior uses local buffering and asynchronous remote work where permitted by the companion. +- `drain-file-system` is FUSE-only. +- Abruptly killing the mount process or deleting a machine can lose uncommitted memory/write-back state. +- The default coding-agent mount profile stores dependency trees, generated output, caches, and Git internals locally. Local-only data disappears when its disk disappears unless it is packed or otherwise preserved. +- A running mount remains on the companion version loaded at mount time. Unmount and remount after updating tdc. +- Remote-committed Filesystem data survives client or sandbox deletion; deleting the machine does not delete the remote resource. + +## Product limitations + +- tdc is Preview and command contracts can change. +- Database management targets TiDB Cloud Starter, not every TiDB Cloud cluster tier. +- SQL execution accepts one statement per invocation. +- Read-write is the default SQL role; use explicit role flags in security-sensitive automation. +- Journals are append-only and the current public command surface has no journal delete command. +- Filesystem resource list and describe commands operate on the local registry; they are not an organization-wide discovery API. +- Telemetry commands, serverless-function deployment, Homebrew, and Scoop distribution are not implemented. +- tdc depends on its installed `tdc-drive9` companion for all public Filesystem runtime behavior. + +## Related documentation + +- [Manage TiDB Cloud Filesystem with tdc](/ai/tdc/guides/tdc-filesystem.md) +- [tdc Configuration and Credentials](/ai/tdc/reference/tdc-configuration-and-credentials.md) +- [Troubleshoot tdc](/ai/tdc/reference/tdc-troubleshooting.md) diff --git a/ai/tdc/reference/tdc-troubleshooting.md b/ai/tdc/reference/tdc-troubleshooting.md new file mode 100644 index 0000000000000..eb73ce5c4fd39 --- /dev/null +++ b/ai/tdc/reference/tdc-troubleshooting.md @@ -0,0 +1,190 @@ +--- +title: Troubleshoot tdc +summary: Diagnose tdc authentication, project, Filesystem selection, companion, quota, SQL user, mount, and interrupted-cleanup failures. +--- + +# Troubleshoot tdc + +Use this guide to diagnose common current tdc failures. Add `--debug` only when needed; debug output is redacted but should still be reviewed before sharing. + +> **Note:** +> +> tdc is currently in Preview. Its features and command-line interface might change without prior notice. + +## API authentication fails + +Symptoms include missing credentials, Digest authentication failure, or permission denied. + +Check that both environment values are set together: + +```bash +test -n "$TDC_PUBLIC_KEY" +test -n "$TDC_PRIVATE_KEY" +``` + +If you intend to use saved credentials, unset both variables and verify the profile: + +```bash +unset TDC_PUBLIC_KEY TDC_PRIVATE_KEY +tdc organization list-projects --profile default +``` + +An API key can authenticate successfully but still lack the permission declared by a command. Use a key with the required organization or project access. + +## Configure cannot find a virtual project + +`tdc configure` requires exactly one accessible project whose `type` is `tidbx_virtual`. + +```bash +tdc organization list-projects \ + --query 'projects[].{id:id,name:name,type:type}' +``` + +If no virtual project appears, confirm the API key's organization and project access. If multiple virtual projects appear, report the ambiguous account state through the [tdc issue tracker](https://github.com/tidbcloud/tdc/issues). + +## Filesystem token is missing + +For a clean sandbox, provide all three values: + +```bash +export TDC_FS_TOKEN="" +export TDC_REGION_CODE="aws-us-east-1" +export TDC_FS_FILE_SYSTEM_NAME="workspace" +tdc fs check-file-system +``` + +The FS token is not the TiDB Cloud API private key. + +## Filesystem selection is ambiguous + +List registered resources and select one explicitly: + +```bash +tdc fs list-file-systems --output text +tdc fs list-files --file-system-name workspace --path / +``` + +Or set a default: + +```bash +tdc fs set-default-file-system --file-system-name workspace +``` + +tdc intentionally does not guess among multiple resources. + +## Filesystem region is unsupported + +The configured TiDB Cloud region might not have a `tidb_cloud_native` Filesystem endpoint. Compare it with [current Filesystem regions](/ai/tdc/reference/tdc-regions-security-and-limitations.md#filesystem-regions). Change placement with a valid profile or command-scoped `--region`; do not configure a raw server URL. + +## Companion is missing or incompatible + +The release installer places `tdc-drive9` next to `tdc`. Re-run the current installer when tdc reports a missing companion: + +```bash +curl -fsSL https://github.com/tidbcloud/tdc/releases/latest/download/install.sh | sh -s -- --yes +``` + +Verify that `PATH` resolves the expected tdc: + +```bash +command -v tdc +tdc --version +``` + +Do not copy an arbitrary standalone Drive9 binary into place. + +## Starter or Filesystem creation reaches quota + +Quota and capacity errors can mean the organization has reached its free Starter limit. List existing resources before creating another: + +```bash +tdc db list-db-clusters --output text +tdc fs list-file-systems --output text +``` + +Never delete an unrelated resource to make automation pass. A Starter spending limit can require configured billing. + +## SQL credentials are missing + +Prepare or repair users for the exact cluster: + +```bash +tdc db create-db-sql-users --db-cluster-id "" +``` + +Then retry with an explicit role: + +```bash +tdc db execute-sql-statement \ + --db-cluster-id "" \ + --read-only \ + --sql "SELECT 1" +``` + +Deleting `~/.tdc/db_users//credentials` removes local passwords. Run the create/repair command rather than inventing credentials. + +## Mount does not become ready + +Inspect the log path printed by the timeout error. Confirm: + +- the mount path exists and is writable; +- no existing mount covers the path; +- the FS token and region are valid; +- FUSE prerequisites or the WebDAV helper are installed; +- the remote region is reachable. + +macOS defaults to WebDAV. To request FUSE after installing macFUSE: + +```bash +tdc fs mount-file-system \ + --mount-path /path/to/workspace \ + --driver fuse +``` + +Linux needs FUSE3 and access to `/dev/fuse`. Windows WebDAV needs the WebClient service and a drive letter such as `X:`. + +## Mount becomes stale after a process crash + +If the companion is killed without graceful unmount, FUSE access can return `EIO` or `Transport endpoint is not connected`. Stop processes with open files, then try: + +```bash +tdc fs unmount-file-system \ + --mount-path /path/to/workspace \ + --force +``` + +Use `--ignore-absent` when cleanup should succeed if no locator remains. Abrupt cleanup cannot guarantee recovery of pending writes from a deleted local disk. + +## Unmount reports busy + +Close editors, shells whose working directory is inside the mount, and other open file handles. For FUSE, drain before retrying: + +```bash +tdc fs drain-file-system --mount-path /path/to/workspace --timeout 30s +tdc fs unmount-file-system --mount-path /path/to/workspace +``` + +Do not use drain for WebDAV. + +## An interrupted command leaves resources + +List resources and identify only those created by your workflow. Use describe before delete: + +```bash +tdc db describe-db-cluster --db-cluster-id "" +tdc fs describe-file-system --file-system-name "" +``` + +Preview supported cleanup: + +```bash +tdc db delete-db-cluster --db-cluster-id "" --dry-run +tdc fs delete-file-system \ + --file-system-name "" \ + --confirm-file-system-name "" \ + --dry-run +``` + +## Report a problem + +Include the tdc version, OS and architecture, command name, stable error code, and redacted logs. Never include API keys, FS or vault tokens, DB passwords, SQL containing private data, or file contents. Report issues at [github.com/tidbcloud/tdc/issues](https://github.com/tidbcloud/tdc/issues). diff --git a/ai/tdc/tdc-overview.md b/ai/tdc/tdc-overview.md new file mode 100644 index 0000000000000..f7d0c0fb2cbdf --- /dev/null +++ b/ai/tdc/tdc-overview.md @@ -0,0 +1,72 @@ +--- +title: TiDB Cloud CLI (tdc) Overview +summary: Learn how the Preview tdc command-line interface manages TiDB Cloud Starter databases and TiDB Cloud Filesystem for users, scripts, and AI agents. +--- + +# TiDB Cloud CLI (tdc) Overview + +tdc is a command-line interface for managing TiDB Cloud Starter databases and TiDB Cloud Filesystem. It provides deterministic JSON output, explicit permissions, scriptable configuration, and commands designed for both users and AI agents. + +> **Note:** +> +> tdc is currently in Preview. Its features and command-line interface might change without prior notice. + +## What you can do with tdc + +With tdc, you can: + +- create, inspect, update, and delete TiDB Cloud Starter clusters; +- create and manage Starter branches; +- create read-only, read-write, and admin SQL users, format connection strings, and execute SQL; +- create and select multiple TiDB Cloud Filesystem resources in one profile; +- access Filesystem data directly or mount it through FUSE or WebDAV; +- use Filesystem layers, packs, Git workspaces, append-only journals, and delegated secrets; +- use JSON output and JMESPath queries in scripts and agent workflows. + +tdc has a two-level command model: + +```text +tdc +``` + +Examples include `tdc db list-db-clusters`, `tdc fs copy-file`, and `tdc fs-journal verify-journal`. The top-level `tdc configure` and `tdc update` commands configure and maintain the CLI. + +## tdc and Drive9 + +tdc installs a bundled [Drive9](https://github.com/mem9-ai/drive9) companion named `tdc-drive9`. tdc owns profile selection, TiDB Cloud credentials, region and Filesystem selection, output formatting, and tdc error behavior. The companion owns Filesystem data-plane semantics, FUSE and WebDAV mounts, layers, pack and unpack, Git workspace acceleration, journals, and vault operations. + +You do not need to install, configure, or invoke Drive9 separately for normal tdc workflows. + +## Start using tdc + +- [Quick Start](/ai/tdc/tdc-quick-start.md) +- [Concepts and Architecture](/ai/tdc/concepts/tdc-concepts-and-architecture.md) + +### Guides + +- [Install, Configure, and Update tdc](/ai/tdc/guides/tdc-install-configure-update.md) +- [Manage TiDB Cloud Organizations](/ai/tdc/guides/tdc-organization.md) +- [Manage TiDB Cloud Starter Databases](/ai/tdc/guides/tdc-starter-database.md) +- [Manage TiDB Cloud Filesystem](/ai/tdc/guides/tdc-filesystem.md) +- [Use Git Workspaces on TiDB Cloud Filesystem](/ai/tdc/guides/tdc-filesystem-git.md) +- [Use Filesystem Journals](/ai/tdc/guides/tdc-filesystem-journal.md) +- [Use Filesystem Vault](/ai/tdc/guides/tdc-filesystem-vault.md) + +### Examples + +- [Use a Filesystem in an Agent Sandbox](/ai/tdc/examples/tdc-agent-sandbox-example.md) +- [Run a Daily tdc Workflow](/ai/tdc/examples/tdc-daily-workflow-example.md) +- [Query SQL with Explicit Roles](/ai/tdc/examples/tdc-query-sql-with-roles-example.md) +- [Share a Filesystem Across Machines](/ai/tdc/examples/tdc-share-filesystem-across-machines-example.md) +- [Prepare a Git Workspace for Agents](/ai/tdc/examples/tdc-git-workspace-for-agents-example.md) +- [Record an Agent Workflow in a Journal](/ai/tdc/examples/tdc-journal-agent-workflow-example.md) +- [Delegate Secrets to an Agent](/ai/tdc/examples/tdc-vault-agent-secrets-example.md) + +### Reference + +- [tdc CLI Reference](/ai/tdc/reference/tdc-cli-reference.md) +- [tdc Configuration and Credentials](/ai/tdc/reference/tdc-configuration-and-credentials.md) +- [tdc Regions, Security, and Limitations](/ai/tdc/reference/tdc-regions-security-and-limitations.md) +- [Troubleshoot tdc](/ai/tdc/reference/tdc-troubleshooting.md) + +To report a problem or suggest an improvement, create an issue in the [tdc GitHub repository](https://github.com/tidbcloud/tdc/issues). diff --git a/ai/tdc/tdc-quick-start.md b/ai/tdc/tdc-quick-start.md new file mode 100644 index 0000000000000..841f6ed4b3c47 --- /dev/null +++ b/ai/tdc/tdc-quick-start.md @@ -0,0 +1,130 @@ +--- +title: Get Started with TiDB Cloud CLI (tdc) +summary: Install and configure tdc, then complete a first TiDB Cloud Starter database or Filesystem operation. +--- + +# Get Started with TiDB Cloud CLI (tdc) + +This quick start installs tdc, configures one profile, and gets a successful result from either TiDB Cloud Starter or TiDB Cloud Filesystem. + +> **Note:** +> +> tdc is currently in Preview. Its features and command-line interface might change without prior notice. + +## Prerequisites + +Before you begin, obtain a TiDB Cloud API public key and private key from the [TiDB Cloud API Keys](https://tidbcloud.com/org-settings/api-keys) page. The key must be able to access a `tidbx_virtual` project. + +## Step 1. Install tdc + +On macOS or Linux: + +```bash +curl -fsSL https://github.com/tidbcloud/tdc/releases/latest/download/install.sh | sh -s -- --yes +export PATH="$HOME/.tdc/bin:$PATH" +tdc --version +``` + +Add `export PATH="$HOME/.tdc/bin:$PATH"` to your shell profile to keep tdc available in new terminals. + +On Windows PowerShell: + +```powershell +$script = "$env:TEMP\install-tdc.ps1" +iwr https://github.com/tidbcloud/tdc/releases/latest/download/install.ps1 -OutFile $script +powershell -ExecutionPolicy Bypass -File $script -Yes +$env:Path = "$HOME\.tdc\bin;$env:Path" +tdc --version +``` + +## Step 2. Configure tdc + +Run the interactive configuration: + +```bash +tdc configure +``` + +Enter your API public key, private key, and a canonical region code such as `aws-us-east-1`. tdc validates the key, discovers the `tidbx_virtual` project, and saves it as the default project. + +Verify the configuration: + +```bash +tdc organization list-projects --output text +``` + +## Step 3. Choose a first workflow + +Complete either the Filesystem workflow or the Starter database workflow. + +### Option A: Write and read a file + +Create a Filesystem and capture its owner token without displaying it: + +```bash +export TDC_FS_TOKEN="$(tdc fs create-file-system \ + --file-system-name quickstart-fs \ + --query fs_token \ + --output text)" +``` + +Write and read a file through the data plane: + +```bash +printf 'hello from tdc\n' | tdc fs copy-file \ + --file-system-name quickstart-fs \ + --from-stdin \ + --to-remote /hello.txt + +tdc fs read-file \ + --file-system-name quickstart-fs \ + --path /hello.txt +``` + +Expected output: + +```text +hello from tdc +``` + +Clean up: + +```bash +tdc fs delete-file-system \ + --file-system-name quickstart-fs \ + --confirm-file-system-name quickstart-fs +unset TDC_FS_TOKEN +``` + +### Option B: Query a Starter database + +List clusters and select an active cluster ID: + +```bash +tdc db list-db-clusters --output text +export TDC_DB_CLUSTER_ID="" +``` + +If the cluster does not yet have tdc-managed SQL users, create them: + +```bash +tdc db create-db-sql-users --db-cluster-id "$TDC_DB_CLUSTER_ID" +``` + +Run a read-only verification query: + +```bash +tdc db execute-sql-statement \ + --db-cluster-id "$TDC_DB_CLUSTER_ID" \ + --read-only \ + --sql "SELECT 1 AS ready" \ + --output text +``` + +The command executes one statement through the HTTPS SQL API and returns a result containing `ready = 1`. + +## What's next + +- [Manage TiDB Cloud Starter Databases](/ai/tdc/guides/tdc-starter-database.md) +- [Manage TiDB Cloud Filesystem](/ai/tdc/guides/tdc-filesystem.md) +- [tdc Configuration and Credentials](/ai/tdc/reference/tdc-configuration-and-credentials.md) From 388e0b6e0a0e57a4fc231d3ded5c70dbc95a0037 Mon Sep 17 00:00:00 2001 From: Cheese Date: Sat, 18 Jul 2026 02:33:12 +0800 Subject: [PATCH 2/3] docs: improve tdc onboarding and examples --- ai/tdc/examples/tdc-agent-sandbox-example.md | 14 +++- .../tdc-git-workspace-for-agents-example.md | 31 +++++++-- .../tdc-journal-agent-workflow-example.md | 14 +++- .../tdc-query-sql-with-roles-example.md | 14 +++- ...hare-filesystem-across-machines-example.md | 14 +++- .../tdc-vault-agent-secrets-example.md | 14 +++- ai/tdc/guides/tdc-filesystem-git.md | 8 ++- ai/tdc/guides/tdc-install-configure-update.md | 14 ++++ .../tdc-configuration-and-credentials.md | 2 +- .../tdc-regions-security-and-limitations.md | 10 ++- ai/tdc/tdc-quick-start.md | 66 +++++++++++++------ 11 files changed, 164 insertions(+), 37 deletions(-) diff --git a/ai/tdc/examples/tdc-agent-sandbox-example.md b/ai/tdc/examples/tdc-agent-sandbox-example.md index 9c080242a49d3..d702c00309fa1 100644 --- a/ai/tdc/examples/tdc-agent-sandbox-example.md +++ b/ai/tdc/examples/tdc-agent-sandbox-example.md @@ -5,12 +5,24 @@ summary: Provision a Filesystem on a trusted machine and give a clean agent sand # Use TiDB Cloud Filesystem in an Agent Sandbox -This example provisions a Filesystem on a trusted machine, transfers the minimum environment to a clean sandbox, and uses tdc without copying `~/.tdc/`. +This example gives an ephemeral coding agent a durable workspace without copying a user's complete tdc configuration into the sandbox. > **Note:** > > tdc is currently in Preview. Its features and command-line interface might change without prior notice. +## The agent problem + +Coding agents often start in clean, short-lived sandboxes. The local disk disappears when the sandbox is replaced, but the agent still needs previous artifacts, repository state, and files produced by other workers. Rebuilding that state wastes task time, while copying `~/.tdc/` or injecting TiDB Cloud API keys gives the sandbox control-plane credentials it does not need. + +## Why local storage and full cloud credentials are not enough + +A sandbox-local directory is fast but not durable or shared. Generic object-storage APIs require application-specific download and upload logic instead of ordinary file operations. Giving every sandbox the user's complete cloud credentials solves access at the cost of a much broader security boundary. + +## How tdc changes the workflow + +A trusted machine provisions the Filesystem once. The sandbox receives only the Filesystem owner token, region code, and Filesystem name, and can immediately use data-plane, mount, Git, journal, and vault workflows without `tdc configure`. When an agent needs only selected secrets, use a delegated vault token instead of the owner token. + ## Prerequisites - Install and configure tdc on a trusted machine. diff --git a/ai/tdc/examples/tdc-git-workspace-for-agents-example.md b/ai/tdc/examples/tdc-git-workspace-for-agents-example.md index 4efb162eae68c..6896ba7222bcd 100644 --- a/ai/tdc/examples/tdc-git-workspace-for-agents-example.md +++ b/ai/tdc/examples/tdc-git-workspace-for-agents-example.md @@ -1,16 +1,28 @@ --- title: Prepare a Git Workspace for Agents on TiDB Cloud Filesystem -summary: Mount a Filesystem, create a fast Git workspace and linked worktree, use Git normally, and clean up safely. +summary: Make a large Git workspace visible quickly, hydrate clean objects in the background, and let an agent start work before the full download finishes. --- # Prepare a Git Workspace for Agents on TiDB Cloud Filesystem -This example prepares a repository and an isolated linked worktree for an agent. +This example removes a large repository clone from the critical path of starting an agent task. > **Note:** > > tdc is currently in Preview. Its features and command-line interface might change without prior notice. +## The agent problem + +An ephemeral agent normally waits for `git clone` and checkout to download a repository before it can inspect the tree or begin work. For a large monorepo, that startup delay is paid again for every replacement sandbox. The agent appears idle even when its first task needs only a small part of the repository. + +## Why a normal clone or partial clone is not enough + +A normal clone blocks until the initial object transfer and checkout finish. A native blobless partial clone reduces the first transfer, but later Git commands and file reads can still trigger many on-demand fetches on the agent's critical path. Neither approach by itself provides a shared Filesystem workspace that can be restored across agent runtimes. + +## How tdc changes the workflow + +`tdc fs-git clone-git-workspace --blobless --hydrate background` registers the Git workspace and exposes its file tree before all clean blobs finish downloading. The command returns so the agent can inspect paths and start working while tdc hydrates the clean tree and local Git object database in the background. Reads that arrive before hydration completes fall back to Git's lazy fetch for correctness. Ordinary Git remains responsible for edits, commits, fetches, and pushes. + ## Prerequisites - Select a Filesystem. @@ -26,22 +38,31 @@ tdc fs mount-file-system \ --driver fuse ``` -## Step 2. Clone and hydrate +## Step 2. Create the workspace and hydrate in the background ```bash tdc fs-git clone-git-workspace \ --repo-url https://github.com/pingcap/tidb.git \ --target-path /path/to/workspace/tidb \ --blobless \ - --hydrate sync + --hydrate background ``` -Verify: +The workspace tree is now available, and hydration continues in the background. Let the agent start with ordinary commands: ```bash +find /path/to/workspace/tidb -maxdepth 2 -type f | head git -C /path/to/workspace/tidb status ``` +Before a deterministic benchmark or before draining the mount, you can wait for hydration explicitly: + +```bash +tdc fs-git hydrate-git-workspace \ + --target-path /path/to/workspace/tidb \ + --timeout 30m +``` + ## Step 3. Create an agent worktree ```bash diff --git a/ai/tdc/examples/tdc-journal-agent-workflow-example.md b/ai/tdc/examples/tdc-journal-agent-workflow-example.md index 788953e6085ca..5b8d4aa01f442 100644 --- a/ai/tdc/examples/tdc-journal-agent-workflow-example.md +++ b/ai/tdc/examples/tdc-journal-agent-workflow-example.md @@ -5,12 +5,24 @@ summary: Create a journal, append structured agent events, search the workflow, # Record an Agent Workflow in a Filesystem Journal -This example records an agent task as structured, ordered events rather than appending unvalidated text to a mutable file. +This example records an agent task as a structured, ordered, and verifiable event history. > **Note:** > > tdc is currently in Preview. Its features and command-line interface might change without prior notice. +## The agent problem + +An agent task can span planning, tool calls, tests, retries, and handoffs between workers. When the task fails, operators need to know which events happened and in what order. Plain console output is often scattered across processes, while a mutable status file shows only the latest state. + +## Why appending to a normal file is not enough + +A text file can be edited or truncated after an event is written, has no intrinsic sequence or hash chain, and requires every producer to invent parsing and concurrency rules. Retrying an append can also create duplicate events unless the application builds its own idempotency layer. + +## How tdc changes the workflow + +A Filesystem journal stores structured append-only entries with sequence information, searchable fields, optional idempotency keys, and hash-chain verification. Agents append semantic events such as `task.started` and `test.finished`; operators can query the workflow and verify the stored chain without treating a mutable log file as evidence. + ## Prerequisites Select a Filesystem through a configured profile or FS token environment. diff --git a/ai/tdc/examples/tdc-query-sql-with-roles-example.md b/ai/tdc/examples/tdc-query-sql-with-roles-example.md index d9289fc297500..f8fb20e3f91f3 100644 --- a/ai/tdc/examples/tdc-query-sql-with-roles-example.md +++ b/ai/tdc/examples/tdc-query-sql-with-roles-example.md @@ -5,12 +5,24 @@ summary: Prepare tdc-managed SQL users and run read-only, read-write, and admin # Query TiDB Cloud Starter with Explicit SQL Roles -This example uses all three tdc-managed SQL roles without exposing generated passwords. +This example lets an agent perform schema, data, and verification work while making the required privilege level explicit for every statement. > **Note:** > > tdc is currently in Preview. Its features and command-line interface might change without prior notice. +## The agent problem + +An agent that can inspect data often also needs to apply a migration or update a row. Giving it one administrator connection for the complete task is convenient, but a mistaken statement during an inspection step then has the authority to change or delete data. Giving it only a read-only connection prevents legitimate write and schema work. + +## Why one native database connection is not enough + +TiDB supports SQL privileges, but a conventional client session uses the privileges of the one credential used to connect. Users must create, store, and switch among credentials themselves, and an agent can silently keep using an overly privileged connection across task phases. + +## How tdc changes the workflow + +`tdc db create-db-sql-users` creates stable read-only, read-write, and admin identities and stores their credentials locally. Each `execute-sql-statement` invocation selects one role explicitly, uses the corresponding credential, and executes one statement. The agent can therefore use admin for schema changes, read-write for data changes, and read-only for verification without handling passwords directly. + ## Prerequisites - Configure tdc. diff --git a/ai/tdc/examples/tdc-share-filesystem-across-machines-example.md b/ai/tdc/examples/tdc-share-filesystem-across-machines-example.md index 32b6d301f67bf..d0028d289b152 100644 --- a/ai/tdc/examples/tdc-share-filesystem-across-machines-example.md +++ b/ai/tdc/examples/tdc-share-filesystem-across-machines-example.md @@ -5,12 +5,24 @@ summary: Create one Filesystem, securely access it from a second machine, and ve # Share a TiDB Cloud Filesystem Across Machines -This example creates a Filesystem on machine A and accesses the same data from machine B without copying a tdc profile. +This example gives agents or users on two machines one shared workspace without copying files between machine-local disks. > **Note:** > > tdc is currently in Preview. Its features and command-line interface might change without prior notice. +## The agent problem + +An agent can prepare source files or artifacts on machine A and continue the task on machine B, but each machine normally sees only its own disk. Copying a snapshot before every handoff adds latency, and changes made after the copy are invisible to the other machine. Concurrent handoffs can also create conflicting copies with no clear source of truth. + +## Why native local disks and manual synchronization are not enough + +Local disks do not provide a shared namespace. Commands such as `scp` and archive upload transfer point-in-time copies rather than live state, while object storage does not by itself behave like the mounted directory expected by editors, build tools, and agents. + +## How tdc changes the workflow + +Both machines select the same TiDB Cloud Filesystem. Data-plane commands and the mounted path address one remote namespace, so a write from either interface becomes visible through the other after it is flushed. Machine B needs only the Filesystem token, region code, and name; it does not need TiDB Cloud API keys or a copied profile. + ## Prerequisites - Machine A has configured tdc. diff --git a/ai/tdc/examples/tdc-vault-agent-secrets-example.md b/ai/tdc/examples/tdc-vault-agent-secrets-example.md index 99bf88c5ab705..1b6efcaad23b4 100644 --- a/ai/tdc/examples/tdc-vault-agent-secrets-example.md +++ b/ai/tdc/examples/tdc-vault-agent-secrets-example.md @@ -5,12 +5,24 @@ summary: Store a secret, grant one field to an agent, inject it into a process, # Delegate Filesystem Vault Secrets to an Agent -This example gives an agent temporary access to one field without sharing the Filesystem owner token. +This example gives an agent temporary access to one secret field without sharing the Filesystem owner token or the complete secret. > **Note:** > > tdc is currently in Preview. Its features and command-line interface might change without prior notice. +## The agent problem + +An agent might need one API endpoint or token to complete a short task. Putting the complete secret in a prompt, `.env` file, or sandbox image exposes it beyond the process and lifetime that need it. Sharing the Filesystem owner token also grants much more access than one secret field requires. + +## Why ordinary environment variables and files are not enough + +Environment variables and files can deliver a secret, but they do not create a scoped, expiring delegation or an access audit trail. A separate cloud secret manager can provide those controls, but it requires another identity, policy, and integration path for every sandbox. + +## How tdc changes the workflow + +The Filesystem owner stores the secret once and creates a short-lived grant scoped to the required field. The agent receives only the delegated vault token and can inject the allowed value into a child process. The owner can inspect audit events and revoke the grant without rotating or exposing the Filesystem owner credential. + ## Prerequisites - Select a Filesystem with owner access. diff --git a/ai/tdc/guides/tdc-filesystem-git.md b/ai/tdc/guides/tdc-filesystem-git.md index 05d41eec7eebc..5772e62c64976 100644 --- a/ai/tdc/guides/tdc-filesystem-git.md +++ b/ai/tdc/guides/tdc-filesystem-git.md @@ -25,17 +25,19 @@ tdc fs-git clone-git-workspace \ --target-path /path/to/workspace/tidb ``` -For a large repository, create a blobless workspace and hydrate synchronously: +For a large repository, create a blobless workspace and hydrate in the background: ```bash tdc fs-git clone-git-workspace \ --repo-url https://github.com/pingcap/tidb.git \ --target-path /path/to/workspace/tidb \ --blobless \ - --hydrate sync + --hydrate background ``` -`--hydrate` accepts `auto`, `background`, `sync`, or `off`. +The command returns after registering the workspace, so the file tree becomes available while clean content and Git objects continue to hydrate. Reads before hydration finishes use Git lazy fetch for correctness. This moves most repository download work out of the agent startup path. + +`--hydrate` accepts `auto`, `background`, `sync`, or `off`. Use `sync` when the caller must wait for hydration before continuing, such as a deterministic benchmark. ## Hydrate an existing workspace diff --git a/ai/tdc/guides/tdc-install-configure-update.md b/ai/tdc/guides/tdc-install-configure-update.md index c0b2166b824ff..bcb1461765708 100644 --- a/ai/tdc/guides/tdc-install-configure-update.md +++ b/ai/tdc/guides/tdc-install-configure-update.md @@ -15,8 +15,15 @@ This guide covers the supported release installers, profile configuration, help ### macOS and Linux +Run the installer: + ```bash curl -fsSL https://github.com/tidbcloud/tdc/releases/latest/download/install.sh | sh -s -- --yes +``` + +After installation, add tdc to the current shell and verify it: + +```bash export PATH="$HOME/.tdc/bin:$PATH" tdc --version ``` @@ -25,10 +32,17 @@ The installer places `tdc` and its `tdc-drive9` companion in `~/.tdc/bin`. Add t ### Windows +Run the installer: + ```powershell $script = "$env:TEMP\install-tdc.ps1" iwr https://github.com/tidbcloud/tdc/releases/latest/download/install.ps1 -OutFile $script powershell -ExecutionPolicy Bypass -File $script -Yes +``` + +After installation, add tdc to the current PowerShell session and verify it: + +```powershell $env:Path = "$HOME\.tdc\bin;$env:Path" tdc --version ``` diff --git a/ai/tdc/reference/tdc-configuration-and-credentials.md b/ai/tdc/reference/tdc-configuration-and-credentials.md index 2fa41a2768b8f..71d4ebc520c52 100644 --- a/ai/tdc/reference/tdc-configuration-and-credentials.md +++ b/ai/tdc/reference/tdc-configuration-and-credentials.md @@ -43,7 +43,7 @@ The profile namespace is selected in this order: 2. `TDC_PROFILE`; 3. `default`. -An explicit empty profile is invalid. Environment credentials do not create an `[env]` profile and do not change the selected namespace. +An explicit empty profile is invalid. ## TiDB Cloud API credentials diff --git a/ai/tdc/reference/tdc-regions-security-and-limitations.md b/ai/tdc/reference/tdc-regions-security-and-limitations.md index 1166cf4d2502d..9b7fed86f189f 100644 --- a/ai/tdc/reference/tdc-regions-security-and-limitations.md +++ b/ai/tdc/reference/tdc-regions-security-and-limitations.md @@ -28,10 +28,14 @@ Alibaba Cloud currently supports only Singapore in tdc. Users cannot configure r ## Filesystem regions -Filesystem endpoint availability is resolved from the hosted Drive9 region manifest. At publication time, TiDB Cloud native Filesystem mode is available for: +Filesystem endpoint availability is resolved from the hosted Drive9 region manifest. At publication time, TiDB Cloud native Filesystem mode is available in: -- `aws-us-east-1`; -- `aws-ap-southeast-1`. +| Cloud provider | Canonical region code | +| --- | --- | +| AWS | `aws-ap-southeast-1` | +| AWS | `aws-us-east-1` | +| AWS | `aws-us-west-2` | +| Alibaba Cloud | `ali-ap-southeast-1` | The hosted manifest is authoritative and can change during Preview. A profile in another TiDB Cloud region can manage Starter databases but receives an unsupported Filesystem endpoint error until that placement appears in the manifest. diff --git a/ai/tdc/tdc-quick-start.md b/ai/tdc/tdc-quick-start.md index 841f6ed4b3c47..1d3907448bfc9 100644 --- a/ai/tdc/tdc-quick-start.md +++ b/ai/tdc/tdc-quick-start.md @@ -13,30 +13,42 @@ This quick start installs tdc, configures one profile, and gets a successful res ## Prerequisites -Before you begin, obtain a TiDB Cloud API public key and private key from the [TiDB Cloud API Keys](https://tidbcloud.com/org-settings/api-keys) page. The key must be able to access a `tidbx_virtual` project. +Before you begin, obtain a TiDB Cloud API public key and private key from the [TiDB Cloud API Keys](https://tidbcloud.com/org-settings/api-keys) page. ## Step 1. Install tdc -On macOS or Linux: +On macOS or Linux, run the installer: ```bash curl -fsSL https://github.com/tidbcloud/tdc/releases/latest/download/install.sh | sh -s -- --yes +``` + +After installation, add tdc to the current shell and verify it: + +```bash export PATH="$HOME/.tdc/bin:$PATH" tdc --version ``` Add `export PATH="$HOME/.tdc/bin:$PATH"` to your shell profile to keep tdc available in new terminals. -On Windows PowerShell: +On Windows PowerShell, run the installer: ```powershell $script = "$env:TEMP\install-tdc.ps1" iwr https://github.com/tidbcloud/tdc/releases/latest/download/install.ps1 -OutFile $script powershell -ExecutionPolicy Bypass -File $script -Yes +``` + +After installation, add tdc to the current PowerShell session and verify it: + +```powershell $env:Path = "$HOME\.tdc\bin;$env:Path" tdc --version ``` +Add `$HOME\.tdc\bin` to your user `PATH` to keep tdc available in new PowerShell sessions. + ## Step 2. Configure tdc Run the interactive configuration: @@ -45,7 +57,7 @@ Run the interactive configuration: tdc configure ``` -Enter your API public key, private key, and a canonical region code such as `aws-us-east-1`. tdc validates the key, discovers the `tidbx_virtual` project, and saves it as the default project. +Enter your API public key, private key, and a canonical region code such as `aws-us-east-1`. Verify the configuration: @@ -59,26 +71,23 @@ Complete either the Filesystem workflow or the Starter database workflow. ### Option A: Write and read a file -Create a Filesystem and capture its owner token without displaying it: +Create a Filesystem and make it the default: ```bash -export TDC_FS_TOKEN="$(tdc fs create-file-system \ +tdc fs create-file-system \ --file-system-name quickstart-fs \ - --query fs_token \ - --output text)" + --set-default \ + --output text ``` -Write and read a file through the data plane: +tdc stores the Filesystem credential locally. Write and read a file directly: ```bash printf 'hello from tdc\n' | tdc fs copy-file \ - --file-system-name quickstart-fs \ --from-stdin \ --to-remote /hello.txt -tdc fs read-file \ - --file-system-name quickstart-fs \ - --path /hello.txt +tdc fs read-file --path /hello.txt ``` Expected output: @@ -93,27 +102,37 @@ Clean up: tdc fs delete-file-system \ --file-system-name quickstart-fs \ --confirm-file-system-name quickstart-fs -unset TDC_FS_TOKEN ``` ### Option B: Query a Starter database -List clusters and select an active cluster ID: +Create a Starter cluster and save its ID: ```bash -tdc db list-db-clusters --output text -export TDC_DB_CLUSTER_ID="" +export TDC_DB_CLUSTER_ID="$(tdc db create-db-cluster \ + --db-cluster-name quickstart-db \ + --db-cluster-type starter \ + --query id \ + --output text)" ``` -If the cluster does not yet have tdc-managed SQL users, create them: +Wait until the cluster is active: ```bash -tdc db create-db-sql-users --db-cluster-id "$TDC_DB_CLUSTER_ID" +until [ "$(tdc db describe-db-cluster \ + --db-cluster-id "$TDC_DB_CLUSTER_ID" \ + --query state \ + --output text)" = "ACTIVE" ]; do + sleep 5 +done ``` -Run a read-only verification query: +Create the SQL users and run a read-only verification query: ```bash +tdc db create-db-sql-users \ + --db-cluster-id "$TDC_DB_CLUSTER_ID" + tdc db execute-sql-statement \ --db-cluster-id "$TDC_DB_CLUSTER_ID" \ --read-only \ @@ -123,6 +142,13 @@ tdc db execute-sql-statement \ The command executes one statement through the HTTPS SQL API and returns a result containing `ready = 1`. +Clean up: + +```bash +tdc db delete-db-cluster --db-cluster-id "$TDC_DB_CLUSTER_ID" +unset TDC_DB_CLUSTER_ID +``` + ## What's next - [Manage TiDB Cloud Starter Databases](/ai/tdc/guides/tdc-starter-database.md) From d9fcf59d0b0ee3efc81b1ad093b75be42bdffac9 Mon Sep 17 00:00:00 2001 From: Cheese Date: Sat, 18 Jul 2026 22:33:24 +0800 Subject: [PATCH 3/3] docs: document unified wait behavior --- ai/tdc/examples/tdc-agent-sandbox-example.md | 1 + ...-share-filesystem-across-machines-example.md | 1 + ai/tdc/guides/tdc-filesystem.md | 8 ++++++-- ai/tdc/guides/tdc-starter-database.md | 10 ++++++---- ai/tdc/tdc-quick-start.md | 17 +++++------------ 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/ai/tdc/examples/tdc-agent-sandbox-example.md b/ai/tdc/examples/tdc-agent-sandbox-example.md index d702c00309fa1..a9da22eec7040 100644 --- a/ai/tdc/examples/tdc-agent-sandbox-example.md +++ b/ai/tdc/examples/tdc-agent-sandbox-example.md @@ -34,6 +34,7 @@ A trusted machine provisions the Filesystem once. The sandbox receives only the ```bash export TDC_FS_TOKEN="$(tdc fs create-file-system \ --file-system-name agent-sandbox \ + --wait \ --query fs_token \ --output text)" ``` diff --git a/ai/tdc/examples/tdc-share-filesystem-across-machines-example.md b/ai/tdc/examples/tdc-share-filesystem-across-machines-example.md index d0028d289b152..b79b1b5a4b2ea 100644 --- a/ai/tdc/examples/tdc-share-filesystem-across-machines-example.md +++ b/ai/tdc/examples/tdc-share-filesystem-across-machines-example.md @@ -34,6 +34,7 @@ Both machines select the same TiDB Cloud Filesystem. Data-plane commands and the ```bash export TDC_FS_TOKEN="$(tdc fs create-file-system \ --file-system-name shared-workspace \ + --wait \ --query fs_token \ --output text)" diff --git a/ai/tdc/guides/tdc-filesystem.md b/ai/tdc/guides/tdc-filesystem.md index 2a3ba4f1dd252..39a4a73addbf7 100644 --- a/ai/tdc/guides/tdc-filesystem.md +++ b/ai/tdc/guides/tdc-filesystem.md @@ -26,14 +26,18 @@ Create a resource and make it the profile default: ```bash tdc fs create-file-system \ --file-system-name workspace \ - --set-default + --set-default \ + --wait ``` +Without `--wait`, tdc returns after Drive9 accepts provisioning. With the flag, tdc waits up to 10 minutes until the root is readable through the public Drive9 data-plane CLI. A failed wait leaves the resource and locally stored credential intact. + The JSON response includes `fs_token`. Capture it without displaying the complete result: ```bash export TDC_FS_TOKEN="$(tdc fs create-file-system \ --file-system-name sandbox \ + --wait \ --query fs_token \ --output text)" ``` @@ -66,7 +70,7 @@ tdc fs delete-file-system \ --confirm-file-system-name workspace ``` -Create and delete support `--dry-run`. Deletion requires TiDB Cloud API keys and a locally registered resource; an FS token alone cannot delete the resource. +Create and delete support `--dry-run`. Deletion requires TiDB Cloud API keys and a locally registered resource; an FS token alone cannot delete the resource. Drive9 deletion is asynchronous, so a successfully accepted request reports `status: "deleting"` while tdc removes the selected local registry entry and credential. ## Select one of multiple Filesystems diff --git a/ai/tdc/guides/tdc-starter-database.md b/ai/tdc/guides/tdc-starter-database.md index 9fd2eb2d8291c..eede33800021c 100644 --- a/ai/tdc/guides/tdc-starter-database.md +++ b/ai/tdc/guides/tdc-starter-database.md @@ -66,10 +66,11 @@ tdc db delete-db-cluster \ --dry-run tdc db delete-db-cluster \ - --db-cluster-id "" + --db-cluster-id "" \ + --wait ``` -tdc resolves the cluster name internally; no name-confirmation flag is required. +tdc resolves the cluster name internally; no name-confirmation flag is required. Without `--wait`, delete returns after TiDB Cloud accepts the asynchronous request. The wait flag waits up to 12 minutes and returns when the cluster is `DELETED` or no longer accessible. ## Manage branches @@ -78,14 +79,15 @@ Create and list branches: ```bash tdc db create-db-cluster-branch \ --db-cluster-id "" \ - --db-cluster-branch-name development + --db-cluster-branch-name development \ + --wait tdc db list-db-cluster-branches \ --db-cluster-id "" \ --page-size 20 ``` -Use `--page-token` to continue a paginated branch list. +Use `--page-token` to continue a paginated branch list. Without `--wait`, branch creation returns after the request is accepted. The wait flag waits up to five minutes for `ACTIVE`. Describe and delete a branch: diff --git a/ai/tdc/tdc-quick-start.md b/ai/tdc/tdc-quick-start.md index 1d3907448bfc9..e0bded03a34db 100644 --- a/ai/tdc/tdc-quick-start.md +++ b/ai/tdc/tdc-quick-start.md @@ -77,6 +77,7 @@ Create a Filesystem and make it the default: tdc fs create-file-system \ --file-system-name quickstart-fs \ --set-default \ + --wait \ --output text ``` @@ -112,21 +113,11 @@ Create a Starter cluster and save its ID: export TDC_DB_CLUSTER_ID="$(tdc db create-db-cluster \ --db-cluster-name quickstart-db \ --db-cluster-type starter \ + --wait \ --query id \ --output text)" ``` -Wait until the cluster is active: - -```bash -until [ "$(tdc db describe-db-cluster \ - --db-cluster-id "$TDC_DB_CLUSTER_ID" \ - --query state \ - --output text)" = "ACTIVE" ]; do - sleep 5 -done -``` - Create the SQL users and run a read-only verification query: ```bash @@ -145,7 +136,9 @@ The command executes one statement through the HTTPS SQL API and returns a resul Clean up: ```bash -tdc db delete-db-cluster --db-cluster-id "$TDC_DB_CLUSTER_ID" +tdc db delete-db-cluster \ + --db-cluster-id "$TDC_DB_CLUSTER_ID" \ + --wait unset TDC_DB_CLUSTER_ID ```