Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
"name": "agents-env",
"source": "./",
"version": "0.3.0",
"version": "0.3.1",
"description": "Skill that teaches an agent to use the agents-env CLI: inject secrets into commands without the value reaching the agent's context, copy global secrets into a project .env value-free, and discover keys without printing them.",
"category": "security",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion .claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "agents-env",
"version": "0.3.0",
"version": "0.3.1",
"description": "Env vars for AI agents: use secrets without ever seeing their values. Teaches the agent to inject API keys/tokens into commands (run + output masking + {{KEY}} substitution), copy secrets from a global store into a project .env without the value passing through context, and discover keys without printing them. Requires the `agents-env` CLI (cargo install agents-env).",
"author": {
"name": "Aiden Ahn",
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "agents-env"
version = "0.3.0"
version = "0.3.1"
edition = "2024"
rust-version = "1.88"
description = "Env vars for AI agents — use secrets without ever seeing them"
Expand Down
5 changes: 4 additions & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Masking only touches the output stream (child → caller); it never alters the i
| `copy <KEY[@tag]…> --to <file>` | Copy secrets from the global store into a local file; values are not printed. `--as NEWKEY` renames. |
| `generate <KEY>` | Add a new random key to the configured global store; refuse existing names and never print the value, even in human mode. |
| `edit` | Open the global store in `$EDITOR`. Human only; refused in agent mode and on non-TTY. |
| `doctor` | Check file permissions, gitignore coverage, stale backups, untagged duplicate keys, Claude Code deny rules. |
| `doctor` | Check global-store syntax/read errors, permissions, gitignore, stale backups, untagged duplicates and Claude Code deny rules. Never prints values or malformed source lines. |
| `config show` / `config path` | Show effective settings or the config path without reading secret values. |
| `config set <key> <value>` / `config reset <key>` | Change one setting or restore its default; refused in agent mode. |

Expand Down Expand Up @@ -101,6 +101,8 @@ from writes. Prefer the default location or a dedicated `~/secrets/` directory.

**Scope and files.** The default scope is the global store. `-l`/`--local` reads `./.env`; `-f <name>` reads `./<name>`, which handles `.env.local`, `.env.production`, and the like.

The reader recognizes existing digit-prefixed names without renaming or rewriting them. New names supplied to `set`, `generate` and `copy --as` still require portable `[A-Za-z_][A-Za-z0-9_]*` identifiers. Use a program's environment API rather than `$NAME` shell syntax for digit-prefixed names.

```
agents-env -f .env.production get DATABASE
```
Expand All @@ -123,6 +125,7 @@ agents-env run SERVICE_API_KEY -- my-service
- Existing names are refused, including empty values, ASCII case variants and tagged duplicate accounts. No existing entry is replaced or commented out.
- Original bytes, comments, CRLF and order remain unchanged; only a separate entry is appended. A missing trailing newline is added as a separator. Before saving, the candidate is parsed again to verify unchanged existing values/tags and a unique, usable new key.
- Malformed lines, invalid UTF-8, NUL and any input whose meaning would change cause refusal before touching the store or backup. Errors name lines/reasons, never values. Comments are annotations and account selectors, not a duplicate-resolution mechanism.
- When syntax blocks generation, use `agents-env doctor` for value-free reasons from the same parser. Do not print or ignore the malformed source line.
- `generate` and `edit` share a stable exclusive lock. A busy store exits 2: retry after the other operation finishes. Retrying an existing name never rotates its key.
- Stores and backups use 0600, new parent directories use 0700. Links, special files and missing Git protection are refused; staging files must also be ignored. Generation backs up, publishes atomically and verifies the persisted key.

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ agents-env run TAVILY_API_KEY@work -- curl -H "Authorization: Bearer {{TAVILY_AP
| `copy <KEY[@tag]…> --to <file>` | 전역 store의 시크릿을 로컬 파일로 복사. 값은 출력하지 않음. `--as NEWKEY`로 키 이름 변경. |
| `generate <KEY>` | 설정된 전역 store에 새 무작위 키를 추가. 기존 이름은 거부하며, 값은 사람/에이전트 모두에게 출력하지 않음. |
| `edit` | 전역 store를 `$EDITOR`로 연다. 사람 전용이며 에이전트 모드·비TTY에서는 거부. |
| `doctor` | 파일 권한, gitignore 커버리지, 오래된 백업, 태그 없는 중복 키, Claude Code deny 규칙 점검. |
| `doctor` | 전역 저장소 문법/읽기 오류, 파일 권한, gitignore, 오래된 백업, 태그 없는 중복 키, Claude Code deny 규칙 점검. 값이나 문제 행 원문은 출력하지 않음. |
| `config show` / `config path` | 시크릿 파일을 읽지 않고 유효 설정과 설정 파일 위치 조회. |
| `config set <key> <value>` / `config reset <key>` | 설정 한 항목을 변경하거나 기본값으로 복원. 에이전트 모드에서는 변경 거부. |

Expand Down Expand Up @@ -99,6 +99,8 @@ agents-env config reset editor

**스코프와 파일.** 기본 스코프는 전역 store다. `-l`/`--local`은 `./.env`를, `-f <name>`은 `./<name>`을 읽어 `.env.local`, `.env.production` 등 여러 파일을 다룬다.

읽기 파서는 기존 파일의 숫자로 시작하는 이름도 인식하며 이름이나 값을 바꾸지 않는다. 새 이름을 받는 `set`, `generate`, `copy --as`는 이식 가능한 `[A-Za-z_][A-Za-z0-9_]*` 형식을 계속 요구한다. 숫자로 시작하는 환경변수는 `$NAME` 셸 문법으로 접근하지 말고 프로그램의 환경변수 API로 사용한다.

```
agents-env -f .env.production get DATABASE
```
Expand All @@ -121,6 +123,7 @@ agents-env run SERVICE_API_KEY -- my-service
- 기존 키가 있으면 빈 값, 대소문자만 다른 이름, 계정 태그가 있는 중복까지 모두 거부한다. 기존 키를 주석 처리하거나 갱신하지 않는다.
- 원본 바이트와 주석, CRLF, 줄 순서를 그대로 두고 마지막에 새 항목만 추가한다. 마지막 개행이 없으면 구분 개행을 추가한다. 완성된 내용을 다시 파싱해 기존 항목의 값과 태그가 같고 새 키가 유일하게 조회되는지 확인한 뒤 저장한다.
- 파싱할 수 없는 줄, 잘못된 UTF-8, NUL 또는 추가 후 의미가 바뀌는 원문이 있으면 파일과 백업을 건드리지 않고 실패한다. 오류에는 값 대신 줄 번호/원인만 표시한다. 주석은 설명과 기존 계정 선택용이지 중복 해결 수단이 아니다.
- 문법 오류로 중단되면 `agents-env doctor`로 같은 파서의 값 없는 진단을 확인한다. 문제가 있는 행의 원문을 출력하거나 무시하지 않는다.
- 잠금은 동시에 실행한 `generate`와 `edit`를 직렬화한다. 사용 중이면 종료 코드 2로 거부하므로 완료 후 재시도한다. 같은 이름으로 재시도해도 이미 만든 키는 바뀌지 않는다.
- 파일과 백업은 0600, 새 상위 폴더는 0700으로 만들고, 링크/특수 파일과 Git 보호가 없는 대상은 거부한다. 임시 파일도 Git에서 제외되어야 한다. 저장 전 백업과 원자적 교체 후 재조회 검증을 거친다.

Expand Down
4 changes: 2 additions & 2 deletions src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ fn candidate(text: &str, path: &Path, key: &str, value: &str) -> Result<String>
));
}
let original = store::EnvFile::parse(path, text);
if let Some(line) = original.unparseable_lines().first() {
if let Some((line, reason)) = original.syntax_issues().next() {
return Err(refused(format!(
"global store line {} is not parseable; no key was added",
"global store line {} is not parseable: {reason}; no key was added",
line + 1
)));
}
Expand Down
43 changes: 28 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ enum Cmd {
Generate { key: String },
/// Open the global store in $EDITOR (humans only — refused in agent mode)
Edit,
/// Audit protection coverage: permissions, gitignore, backups, dup keys
/// Audit syntax, permissions, gitignore, backups and duplicate keys without printing values
Doctor,
}

Expand Down Expand Up @@ -653,8 +653,11 @@ fn cmd_edit() -> i32 {
// Post-edit lint: keep the KEY@tag selector scheme intact. Names and line
// numbers only — never values.
if let Ok(f) = EnvFile::load(&path) {
for idx in f.unparseable_lines() {
println!("{YELLOW}lint:{RESET} line {} is not parseable", idx + 1);
for (index, reason) in f.syntax_issues() {
println!(
"{YELLOW}lint:{RESET} line {} is not parseable: {reason}",
index + 1
);
}
let mut seen: Vec<String> = Vec::new();
for (i, e) in f.entries() {
Expand Down Expand Up @@ -694,21 +697,31 @@ fn cmd_doctor() -> i32 {
warnings += 1;
println!(" warn: permissions {mode:o} — consider chmod 600");
}
if let Ok(f) = EnvFile::load(&gpath) {
let mut seen: Vec<String> = Vec::new();
for (_, e) in f.entries() {
if f.occurrences(&e.key).len() > 1
&& e.comment.is_none()
&& !seen.contains(&e.key)
{
seen.push(e.key.clone());
match EnvFile::load(&gpath) {
Ok(f) => {
for (index, reason) in f.syntax_issues() {
warnings += 1;
println!(
" warn: duplicate key {} has untagged entries (KEY@tag selection)",
e.key
);
println!(" warn: line {} is not parseable: {reason}", index + 1);
}
let mut seen: Vec<String> = Vec::new();
for (_, e) in f.entries() {
if f.occurrences(&e.key).len() > 1
&& e.comment.is_none()
&& !seen.contains(&e.key)
{
seen.push(e.key.clone());
warnings += 1;
println!(
" warn: duplicate key {} has untagged entries (KEY@tag selection)",
e.key
);
}
}
}
Err(_) => {
warnings += 1;
println!(" warn: cannot read global store as UTF-8; no contents were printed");
}
}
}
Err(_) => {
Expand Down
Loading
Loading