Metadata-Version: 2.4
Name: chatenv
Version: 0.1.0
Summary: ChatArch typed environment profile manager
Author-email: rexwzh <1073853456@qq.com>
License-Expression: MIT
Keywords: chatenv,chatarch,env
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click>=8.0
Requires-Dist: python-dotenv>=1.0
Provides-Extra: dev
Requires-Dist: build>=1.0; extra == "dev"
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: twine>=5.0; extra == "dev"
Provides-Extra: docs
Requires-Dist: mkdocs>=1.6; extra == "docs"
Requires-Dist: mkdocs-material>=9.5; extra == "docs"
Requires-Dist: mkdocs-minify-plugin>=0.8; extra == "docs"
Requires-Dist: mkdocs-redirects>=1.2; extra == "docs"
Requires-Dist: mike>=2.1; extra == "docs"
Dynamic: license-file

<div align="center">
    <a href="https://pypi.python.org/pypi/chatenv">
        <img src="https://img.shields.io/pypi/v/chatenv.svg" alt="PyPI version" />
    </a>
    <a href="https://github.com/ChatArch/ChatEnv/actions/workflows/ci.yml">
        <img src="https://github.com/ChatArch/ChatEnv/actions/workflows/ci.yml/badge.svg" alt="Tests" />
    </a>
    <a href="https://pypi.python.org/pypi/chatenv">
        <img src="https://img.shields.io/pypi/pyversions/chatenv.svg" alt="Python versions" />
    </a>
    <a href="LICENSE">
        <img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License" />
    </a>
</div>

<div align="center">

# ChatEnv

ChatArch typed env/profile runtime.

</div>

ChatEnv 是 ChatArch / chatxxx 系列项目共用的 typed env/profile 底层包。它只提供字段描述、配置基类、registry、路径、profile 文件读写、mask 和 paste 解析等通用能力；具体变量由 ChatTool、ChatDNS 等项目自己定义并注册。

当前设计保持减法：只使用一个根变量 `CHATARCH_HOME`，只管理 env/profile 文件，不额外创建 config/cache/data/state。

支持 Python `>=3.10`。

## 安装

```bash
pip install chatenv --upgrade
pip install -e .[dev]       # 仓库开发
```

## 目录

```text
CHATARCH_HOME=${CHATARCH_HOME:-~/.chatarch}
$CHATARCH_HOME/envs/
```

实际布局由业务项目注册的 schema 决定，例如：

```text
~/.chatarch/envs/
  Example/
    .env
    work.env
```

- `.env` 是当前 active profile；
- `name.env` 是 named profile；
- `use` 会把 named profile 复制为 active `.env`。

## CLI 概览

`chatenv` CLI 基于已注册 schema 工作。单独安装且没有项目注册 schema 时，它会提示需要先注册配置类型。业务项目通常会在自己的 CLI 中导入 schema 后复用这些能力。

```bash
chatenv init -t example
chatenv cat -t example
chatenv cat -t example --no-mask | chatenv paste --stdin --profile work --yes
chatenv set EXAMPLE_API_KEY=sk-xxx
chatenv get EXAMPLE_API_KEY
chatenv new -t example work
chatenv save -t example work
chatenv use -t example work
chatenv delete -t example work
```

单次命令可通过 `--home` 覆盖根目录：

```bash
chatenv --home /tmp/chatarch cat -t example
```

更多用法见 `docs/cli.md`。

## Paste

`paste` 是跨设备复制密钥的核心入口。输入不要求是严格 dotenv 文件，会从终端日志、shell prompt、复制文本里提取已注册 key。

```bash
chatenv paste
chatenv paste --stdin --profile work
chatenv paste --value "EXAMPLE_API_KEY='sk-xxx'" --yes
```

写入前会输出识别概要：识别到哪些类型、哪些 key、未知 key 被忽略。

## Python API

```python
from chatenv import BaseEnvConfig, EnvField, EnvStore, get_paths

class ExampleConfig(BaseEnvConfig):
    _title = "Example Configuration"
    _aliases = ["example"]
    _storage_dir = "Example"

    EXAMPLE_API_KEY = EnvField("EXAMPLE_API_KEY", is_sensitive=True)

paths = get_paths()
store = EnvStore(paths.envs_dir)
store.save_active(ExampleConfig, {"EXAMPLE_API_KEY": "sk-..."})
```

## 文档

- `docs/cli.md`：CLI 用法
- `docs/design.md`：路径、数据布局与注册策略
- `docs/development.md`：测试、构建与发布
- `mkdocs.yml`：Material for MkDocs 文档站点配置

## 开发

```bash
python -m pytest -q
python -m build
python -m twine check dist/*
python -m pip install -e .[docs]
python -m mkdocs serve
```

也可以用 ChatTool helper：

```bash
chattool pypi build --project-dir .
chattool pypi check --project-dir .
```

## 开源协议

MIT License
