Skip to main content

ChatEnv

ChatArch typed env/profile runtime.

ChatEnv 是 ChatArch / chatxxx 系列项目共用的 typed env/profile 底层包。它提供字段描述、配置基类、registry、路径、profile 文件读写、mask、paste 解析,以及 runtime token-store 的通用能力;具体业务变量、登录刷新和连通性语义由各项目自己定义并注册。

文档入口:https://arch.gh.wzhecnu.cn/ChatEnv/

安装

pip install chatenv --upgrade
chatenv --version
chatenv --tree
chatenv --tree-brief

支持 Python >=3.10。

目录

CHATARCH_HOME=${CHATARCH_HOME:-~/.chatarch}
$CHATARCH_HOME/envs/      # stable typed env/profile files
$CHATARCH_HOME/tokens/    # generated runtime tokens/sessions, parallel to env profiles

ChatEnv 只负责 stable env/profile 与 runtime token-store 的存储规则,不额外创建 config/cache/data/state,也不把 tokens/ 当作第二个手工维护 secret/env 层。

自动补问设置

CHATARCH_AUTO_PROMPT 是 ChatEnv 内置、非敏感的 ChatArch typed 字段,默认字符串值为 true。它的 active profile 固定存储在 $CHATARCH_HOME/envs/ChatArch/.env,类型别名为 chatarch:

chatenv set CHATARCH_AUTO_PROMPT=false
chatenv cat -t chatarch

当 ChatEnv 缺少需要补问的命令输入时,优先级依次为显式 -i/-I、进程环境变量 CHATARCH_AUTO_PROMPT、所选 home 下的 ChatArch/.env active profile、默认值 true。-i 仍要求可交互 TTY;-I 始终禁用补问。0、false、no、off 关闭默认补问,其他字符串保持启用语义。

active-profile 集成目前只由 ChatEnv CLI 实现;其他 ChatArch CLI 仍需自行接入该 profile。进程环境变量仍是可供已支持它的 CLI 共享的覆盖方式。

CLI 树

chatenv --tree 从当前安装包的 Click 注册表实时输出带参数签名的完整命令面;chatenv --tree-brief 读取同一注册表,但省略参数签名。

测试当前或命名配置:chatenv test -t example / chatenv test -t example work / chatenv test -t example --profile work。命名 profile 只使用自身字段与 schema 默认值,不切换 active,也不借用默认凭据。

chatenv
├── --help  # Show this message and exit.
├── --version  # Show the version and exit.
├── --tree  # Print the registered command tree.
├── --tree-brief  # Print the registered command tree without parameter signatures.
├── --home HOME  # Override CHATARCH_HOME for this command.
├── init [--type CONFIG-TYPES] [--interactive]  # Create or update active typed env files.
├── new [NAME] [--type CONFIG-TYPES] [--yes] [--interactive]  # Create a named typed profile without activating it.
├── paste [--value VALUE] [--stdin] [--profile PROFILE] [--yes] [--interactive]  # Paste loose env text and import recognized keys.
├── use [NAME] [--type CONFIG-TYPES] [--interactive]  # Activate a named profile for one config type.
├── list [--type CONFIG-TYPES]  # List active default and named profiles grouped by config type.
├── status [--type CONFIG-TYPES] [--detail]  # Show registered config platforms and provider ownership.
├── token  # Manage generic runtime token profiles.
│   ├── status <SERVICE> [PROFILE] [--format OUTPUT-FORMAT]  # Show safe runtime token metadata for SERVICE/PROFILE.
│   ├── refresh <SERVICE> [PROFILE] [--format OUTPUT-FORMAT]  # Refresh SERVICE/PROFILE through a registered service refresh provider.
│   ├── import <SERVICE> [PROFILE] [--stdin] [--file VALUE-FILE] [--token-type TOKEN-TYPE] [--summary SUMMARY] [--expires-at EXPIRES-AT] [--format OUTPUT-FORMAT]  # Explicitly import externally refreshed runtime token JSON.
│   ├── list [SERVICE] [--format OUTPUT-FORMAT]  # List runtime token profiles grouped by service.
│   └── clear <SERVICE> [PROFILE] [--execute] [--format OUTPUT-FORMAT]  # Clear a generic runtime token file for SERVICE/PROFILE.
├── cat [NAME] [--no-mask] [--type CONFIG-TYPES]  # Print active values, or a named typed profile with -t TYPE NAME.
├── get [KEY] [--interactive]  # Get a configuration value from active typed env files.
├── set [KEY-VALUE] [--interactive]  # Set a configuration value in the matching active typed env file.
├── save [NAME] [--type CONFIG-TYPES] [--yes] [--interactive]  # Save current active values as a named profile.
├── delete [NAME] [--type CONFIG-TYPES] [--yes] [--interactive]  # Delete a named profile for one config type.
└── test [PROFILE] [--target TARGET] [--profile NAME] [--interactive]  # Test active configuration or a named PROFILE for one target.

常用命令

chatenv init -t example
chatenv status --detail
chatenv cat -t example
chatenv paste --stdin --profile work --yes
chatenv set EXAMPLE_API_KEY=sk-xxx
chatenv get EXAMPLE_API_KEY
chatenv token refresh PyPI RexWzh
chatenv token status PyPI RexWzh

敏感值默认完整遮罩:init 的已有值提示、默认 cat 和 status --detail 不展示密码/密钥的首尾片段;明确使用 cat --no-mask 才主动取原值。遮罩仅影响显示,不把星号写回 profile;token status/list/clear 只输出 safe metadata,不输出 raw token/cookie/CSRF values。

配置类型精确选择

-t/--type 对每个选择词先匹配完整类型名、存储名或别名;没有精确匹配时才回退前缀匹配。匹配不区分大小写。多个选择词合并并去重,真正重名或前缀匹配多个类型时,要求单类型的命令仍会拒绝歧义。

例如安装 ChatCRS 后,chatenv status -t crs 和 chatenv status -t chatcrs 只选 CRS;-t codex 和 -t chatcrs-codex 只选 Codex。旧别名和 profile/token 存储目录不变,不会隐式切换配置。

Python API

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-..."})

文档

  • https://arch.gh.wzhecnu.cn/ChatEnv/
  • docs/cli.md:CLI 用法
  • docs/design.md:路径、数据布局与注册策略
  • docs/developer-guide.md:chatxxx 项目接入和 provider 开发指南
  • docs/development.md:测试、构建与发布

开发

python -m pip install -e .[dev,docs]
python -m pytest -q
python -m mkdocs build --strict
python -m build
python -m twine check dist/*

开源协议

MIT License

Metadata

Release files for chatenv 0.2.16

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chatenv 0.2.16
File Size Uploaded Provenance Actions
chatenv-0.2.16.tar.gz 42.1 kB With provenance Details for chatenv-0.2.16.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for chatenv 0.2.16
File Interpreter ABI Platform Actions
chatenv-0.2.16-py3-none-any.whl Python 3 none any Details for chatenv-0.2.16-py3-none-any.whl

Total release size: 72.0 kB

Release files / chatenv-0.2.16.tar.gz

Download URL chatenv-0.2.16.tar.gz
Size 42.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6fc87a0d7007990f4a8c05409c3db987593dd8840cc239cb284fb3d44b95d502
BLAKE2b-256 checksum
How to use checksums
b47cc838c46888dc988a82e6480c47396fa0f457c800cc6c2295f72219b06c15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Release files / chatenv-0.2.16-py3-none-any.whl

Download URL chatenv-0.2.16-py3-none-any.whl
Size 29.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a040657d95c4d53a7997c504b1fa5a3c242ad735ccfab2ecf37df72b89a10206
BLAKE2b-256 checksum
How to use checksums
479f01bce7d02cf992c035e2f438eaaac2c71c91ef64c5f541b2357cc00b341f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Security for chatenv 0.2.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for chatenv-0.2.16.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page