feat(kugetsu): add env pass-through for agent delegation #91

Closed
shoko wants to merge 0 commits from feat/issue-76-env-v2 into main
Owner

Summary

Add environment variable management for delegating to agents.

Features

Commands

  • kugetsu env list - List all env files
  • kugetsu env show [agent] - Show env file contents (masked)
  • kugetsu env set <key> <value> [agent] - Set key=value
  • kugetsu env get <key> [agent] - Get value for key
  • kugetsu env rm <key> [agent] - Remove key

Sensitive Value Masking

Masks: GITEA_TOKEN, GITHUB_TOKEN, GITLAB_TOKEN, API_KEY, PASSWORD, TOKEN, SECRET

cmd_delegate

Loads pm-agent.env (or default.env) before running opencode.

Usage

# Set GITEA_TOKEN for PM agent
kugetsu env set GITEA_TOKEN your_token pm-agent

# Verify (token masked)
kugetsu env show pm-agent

# Delegate - agent will have GITEA_TOKEN
kugetsu delegate "post comment on #69"

Fixes #76

## Summary Add environment variable management for delegating to agents. ## Features ### Commands - `kugetsu env list` - List all env files - `kugetsu env show [agent]` - Show env file contents (masked) - `kugetsu env set <key> <value> [agent]` - Set key=value - `kugetsu env get <key> [agent]` - Get value for key - `kugetsu env rm <key> [agent]` - Remove key ### Sensitive Value Masking Masks: GITEA_TOKEN, GITHUB_TOKEN, GITLAB_TOKEN, API_KEY, PASSWORD, TOKEN, SECRET ### cmd_delegate Loads pm-agent.env (or default.env) before running opencode. ## Usage ```bash # Set GITEA_TOKEN for PM agent kugetsu env set GITEA_TOKEN your_token pm-agent # Verify (token masked) kugetsu env show pm-agent # Delegate - agent will have GITEA_TOKEN kugetsu delegate "post comment on #69" ``` Fixes #76
shoko added 1 commit 2026-04-02 02:30:43 +02:00
Add environment variable management for delegating to agents.

Features:
- Add ENV_DIR constant (\~/.kugetsu/env)
- Add mask_sensitive_vars() to hide sensitive values in logs
- Add load_agent_env() to load agent-specific env files
- Add cmd_env command for managing env files:
  - list: List all env files
  - show [agent]: Show env file contents (masked)
  - set <key> <value> [agent]: Set key=value
  - get <key> [agent]: Get value for key
  - rm <key> [agent]: Remove key
- Update cmd_delegate to load pm-agent.env or default.env before running

Example usage:
  kugetsu env set GITEA_TOKEN xxx pm-agent
  kugetsu delegate "post comment on #69"

Fixes #76
shoko added 1 commit 2026-04-02 02:35:50 +02:00
Update cmd_init to create:
- ~/.kugetsu/env/ directory
- ~/.kugetsu/env/default.env (template)
- ~/.kugetsu/env/pm-agent.env (template)

Users can then edit these files to add their tokens/secrets.
First-time contributor

we also need this updated at SKILL.md as well so agent can pick it up that we have env command to manage env rather than injecting them manually on each command

we also need this updated at SKILL.md as well so agent can pick it up that we have env command to manage env rather than injecting them manually on each command
Author
Owner

@han Good point! Updating SKILL.md to document the env command for agents.

@han Good point! Updating SKILL.md to document the env command for agents.
shoko added 1 commit 2026-04-02 02:37:29 +02:00
Add section on Environment Variables for Agents:
- Explain env files (default.env, pm-agent.env)
- Document kugetsu env commands (list, show, set, get, rm)
- Show example usage for GITEA_TOKEN
- Note sensitive value masking
- Explain delegation usage

This ensures agents know to use kugetsu env instead of manually
injecting variables on each command.
shoko added 1 commit 2026-04-02 02:42:36 +02:00
The issue: variables sourced in cmd_delegate were not being passed
to child processes (subagents) because 'source' doesn't automatically
export variables to child processes.

Fix:
1. Use 'set -a' before sourcing to auto-export all variables
2. Use 'set +a' after sourcing to disable auto-export
3. Updated template comments to recommend 'export' prefix

Also added unit test to verify env pass-through works.

Verified with tests that child processes now see the exported variables.
shoko added 1 commit 2026-04-02 02:46:13 +02:00
Add tests for env pass-through feature:
- Test env command exists and lists files
- Test env set creates env file
- Test env show masks sensitive values (GITEA_TOKEN)
- Test set -a exports variables to child processes
- Test pm-agent.env takes precedence over default.env
- Test cmd_init creates env template files

These tests ensure the env pass-through mechanism works correctly
and that variables are properly exported to subagents.
han approved these changes 2026-04-02 02:49:22 +02:00
han left a comment
First-time contributor

lgtm

lgtm
shoko closed this pull request 2026-04-02 02:49:58 +02:00
shoko deleted branch feat/issue-76-env-v2 2026-04-02 02:49:58 +02:00

Pull request closed

Sign in to join this conversation.