workspace-cli

workspace-cli 技术实现方案

1. 技术栈

2. 目录布局

项目源码布局:

cmd/workspace/main.go
internal/agent
internal/cli
internal/config
internal/git
internal/store
internal/workspace
docs

运行时默认目录:

~/.workspace-cli/
  config.yaml
  workspace.db
  work/
    repos/
      <repo>.git
    requirements/
      <req-slug>/
        <repo>/
    releases/
      <release-slug>/
        <repo>/
        .publish/
          <repo>/

测试和自动化可通过 WORKSPACE_CLI_HOME 或 CLI 的全局 --home 指定隔离目录。home 解析优先级为:--home > WORKSPACE_CLI_HOME > ~/.workspace-cli。

3. CLI 命令面

workspace [--home <path>] <command>

workspace init

workspace repo add <name> <url> [--remote origin] [--base <branch>]
workspace repo list [--all]
workspace repo sync [name]
workspace repo update <name> [--url <url>] [--remote <remote>] [--base <branch>]
workspace repo remove <name>

workspace req create <title> --repo <name> [--repo <name>] [--key <slug>]
workspace req list [--all]
workspace req show <key-or-slug>
workspace req update <key-or-slug> [--title <title>]
workspace req add-repo <key-or-slug> <repo>
workspace req archive <key-or-slug>
workspace req finish <key-or-slug> [-m <commit-message>]
workspace req reopen <key-or-slug>

workspace release create <name> --req <key> [--req <key>] [--key <slug>]
workspace release list [--all]
workspace release show <key-or-slug>
workspace release add-req <release> <req>
workspace release remove-req <release> <req>
workspace release status <release>
workspace release integrate <release> [--force]
workspace release publish <release> --tested [-m <message>]

workspace dev <key-or-slug> --tool codex|claude
workspace ide <key-or-slug> [--tool vscode|cursor|zed]

Cobra 层只负责参数解析、加载配置、构造 service 和输出结果。业务规则放到 internal/workspace。workspace release ... 和 workspace req reopen 是 release 流程的当前命令面。

4. 数据模型

SQLite 表:

索引和约束:

迁移与兼容策略:

状态约定:

5. Git 编排

Git 操作统一封装在 internal/git:

策略:

Release Git 策略:

6. 核心服务

internal/workspace.Service 负责:

错误原则:

7. Agent 与 IDE 启动

internal/agent 根据配置启动工具:

8. 测试方案

单元测试:

Git 集成测试:

失败场景:

CLI 测试: