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
9 changes: 0 additions & 9 deletions credentials/templates/devcontainer.env.template

This file was deleted.

19 changes: 0 additions & 19 deletions credentials/templates/mcp.env.template

This file was deleted.

20 changes: 0 additions & 20 deletions dot/config/agent-deck/config.toml

This file was deleted.

2 changes: 0 additions & 2 deletions dot/config/codespaces-secrets/repos.txt

This file was deleted.

15 changes: 10 additions & 5 deletions nix/home/dotfiles.nix
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
{ configRoot, ... }:
{ config, configRoot, ... }:

let
managedSource = source: {
inherit source;
force = true;
};
# 組織情報を含む設定は keito4/private-config(別リポジトリ・非公開)で管理し、
# ローカルチェックアウトを out-of-store symlink で参照する(編集は rebuild 不要で即反映)
privateConfig = path: {
source = config.lib.file.mkOutOfStoreSymlink "/Users/keito/develop/github.com/keito4/private-config/${path}";
force = true;
};
in
{
home.file = {
".aerospace.toml" = managedSource (configRoot + /dot/aerospace.toml);

".config/act/actrc" = managedSource (configRoot + /dot/config/act/actrc);
".config/agent-deck/config.toml" = managedSource (configRoot + /dot/config/agent-deck/config.toml);
".config/codespaces-secrets/repos.txt" = managedSource (
configRoot + /dot/config/codespaces-secrets/repos.txt
);
".config/agent-deck/config.toml" = privateConfig "agent-deck/config.toml";
".config/codespaces-secrets/repos.txt" = privateConfig "codespaces-secrets/repos.txt";
".config/devcontainer-env-keys.txt" = privateConfig "devcontainer-env-keys.txt";
".config/graphite/aliases" = managedSource (configRoot + /dot/config/graphite/aliases);

".gitignore" = managedSource (configRoot + /git/gitignore);
Expand Down
30 changes: 16 additions & 14 deletions nix/home/zsh.nix
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,24 @@
".zsh/configs/pre/devcontainer-env.zsh" = {
text = ''
# Expose selected shared local secrets to CLI tools such as Codex MCP servers.
# NOTE: This list is duplicated in .zsh/configs/pre/devcontainer-env.zsh. Keep both in sync.
# Clear previously exported tokens so removed entries in ~/.devcontainer.env don't linger.
unset SUPABASE_ACCESS_TOKEN VERCEL_TOKEN LINEAR_API_KEY DOPPLER_TOKEN
if [[ -r "$HOME/.devcontainer.env" ]]; then
while IFS='=' read -r _codex_env_key _codex_env_value || [[ -n $_codex_env_key ]]; do
# Strip trailing CR so Windows-style CRLF files work correctly.
_codex_env_value="''${_codex_env_value%$'\r'}"
case "$_codex_env_key" in
# Allowed keys: SUPABASE_ACCESS_TOKEN | VERCEL_TOKEN | LINEAR_API_KEY | DOPPLER_TOKEN
SUPABASE_ACCESS_TOKEN|VERCEL_TOKEN|LINEAR_API_KEY|DOPPLER_TOKEN)
# 許可キー一覧は組織名を含むため private-config 管理の外部ファイルに置く
_codex_env_allowlist="$HOME/.config/devcontainer-env-keys.txt"
if [[ -r "$_codex_env_allowlist" ]]; then
# Clear previously exported tokens so removed entries in ~/.devcontainer.env don't linger.
while IFS= read -r _codex_env_key || [[ -n $_codex_env_key ]]; do
[[ -n $_codex_env_key && $_codex_env_key != \#* ]] && unset "$_codex_env_key"
done < "$_codex_env_allowlist"
if [[ -r "$HOME/.devcontainer.env" ]]; then
while IFS='=' read -r _codex_env_key _codex_env_value || [[ -n $_codex_env_key ]]; do
# Strip trailing CR so Windows-style CRLF files work correctly.
_codex_env_value="''${_codex_env_value%$'\r'}"
if [[ -n $_codex_env_key && $_codex_env_key != \#* ]] && grep -qxF -- "$_codex_env_key" "$_codex_env_allowlist"; then
export "$_codex_env_key=$_codex_env_value"
;;
esac
done < "$HOME/.devcontainer.env"
unset _codex_env_key _codex_env_value
fi
done < "$HOME/.devcontainer.env"
fi
fi
unset _codex_env_key _codex_env_value _codex_env_allowlist
Comment on lines +122 to +139

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

CRLF normalization is asymmetric: allowlist file keys aren't CR-stripped.

Line 132 strips a trailing \r from .devcontainer.env values, but the allowlist read on Line 126 and the grep -qxF match on Line 133 use the allowlist file as-is. If devcontainer-env-keys.txt is saved with CRLF endings, each allowlist line is KEY\r, so grep -x against the CR-stripped KEY fails and matching keys are silently never exported (and Line 127 would unset "KEY$'\r'"). Since the env file already gets CRLF handling, the allowlist should too for consistency.

🔧 Proposed fix to normalize allowlist keys
         if [[ -r "$_codex_env_allowlist" ]]; then
           # Clear previously exported tokens so removed entries in ~/.devcontainer.env don't linger.
           while IFS= read -r _codex_env_key || [[ -n $_codex_env_key ]]; do
+            _codex_env_key="''${_codex_env_key%$'\r'}"
             [[ -n $_codex_env_key && $_codex_env_key != \#* ]] && unset "$_codex_env_key"
           done < "$_codex_env_allowlist"
           if [[ -r "$HOME/.devcontainer.env" ]]; then
             while IFS='=' read -r _codex_env_key _codex_env_value || [[ -n $_codex_env_key ]]; do
               # Strip trailing CR so Windows-style CRLF files work correctly.
+              _codex_env_key="''${_codex_env_key%$'\r'}"
               _codex_env_value="''${_codex_env_value%$'\r'}"
-              if [[ -n $_codex_env_key && $_codex_env_key != \#* ]] && grep -qxF -- "$_codex_env_key" "$_codex_env_allowlist"; then
+              if [[ -n $_codex_env_key && $_codex_env_key != \#* ]] && grep -qxF -- "$_codex_env_key" <(tr -d '\r' < "$_codex_env_allowlist"); then
                 export "$_codex_env_key=$_codex_env_value"
               fi
             done < "$HOME/.devcontainer.env"
           fi
         fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# 許可キー一覧は組織名を含むため private-config 管理の外部ファイルに置く
_codex_env_allowlist="$HOME/.config/devcontainer-env-keys.txt"
if [[ -r "$_codex_env_allowlist" ]]; then
# Clear previously exported tokens so removed entries in ~/.devcontainer.env don't linger.
while IFS= read -r _codex_env_key || [[ -n $_codex_env_key ]]; do
[[ -n $_codex_env_key && $_codex_env_key != \#* ]] && unset "$_codex_env_key"
done < "$_codex_env_allowlist"
if [[ -r "$HOME/.devcontainer.env" ]]; then
while IFS='=' read -r _codex_env_key _codex_env_value || [[ -n $_codex_env_key ]]; do
# Strip trailing CR so Windows-style CRLF files work correctly.
_codex_env_value="''${_codex_env_value%$'\r'}"
if [[ -n $_codex_env_key && $_codex_env_key != \#* ]] && grep -qxF -- "$_codex_env_key" "$_codex_env_allowlist"; then
export "$_codex_env_key=$_codex_env_value"
;;
esac
done < "$HOME/.devcontainer.env"
unset _codex_env_key _codex_env_value
fi
done < "$HOME/.devcontainer.env"
fi
fi
unset _codex_env_key _codex_env_value _codex_env_allowlist
# 許可キー一覧は組織名を含むため private-config 管理の外部ファイルに置く
_codex_env_allowlist="$HOME/.config/devcontainer-env-keys.txt"
if [[ -r "$_codex_env_allowlist" ]]; then
# Clear previously exported tokens so removed entries in ~/.devcontainer.env don't linger.
while IFS= read -r _codex_env_key || [[ -n $_codex_env_key ]]; do
_codex_env_key="''${_codex_env_key%$'\r'}"
[[ -n $_codex_env_key && $_codex_env_key != \#* ]] && unset "$_codex_env_key"
done < "$_codex_env_allowlist"
if [[ -r "$HOME/.devcontainer.env" ]]; then
while IFS='=' read -r _codex_env_key _codex_env_value || [[ -n $_codex_env_key ]]; do
# Strip trailing CR so Windows-style CRLF files work correctly.
_codex_env_key="''${_codex_env_key%$'\r'}"
_codex_env_value="''${_codex_env_value%$'\r'}"
if [[ -n $_codex_env_key && $_codex_env_key != \#* ]] && grep -qxF -- "$_codex_env_key" <(tr -d '\r' < "$_codex_env_allowlist"); then
export "$_codex_env_key=$_codex_env_value"
fi
done < "$HOME/.devcontainer.env"
fi
fi
unset _codex_env_key _codex_env_value _codex_env_allowlist
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@nix/home/zsh.nix` around lines 122 - 139, The allowlist handling in the zsh
env-loading block is asymmetrically handling CRLF, so keys from
devcontainer-env-keys.txt can retain a trailing carriage return and fail both
the unset and grep -qxF checks. Update the allowlist-read path in the zsh setup
logic to normalize keys by stripping trailing CR before using them, and ensure
the matching/unset logic in the block around _codex_env_allowlist,
_codex_env_key, and the grep/export flow compares CR-free keys consistently with
the .devcontainer.env parsing.

'';
};

Expand Down
22 changes: 22 additions & 0 deletions nix/hosts/darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,28 @@
'';
};

# Agent Deck Web UI (headless) — http://127.0.0.1:8420
# loopback バインドのみ。外部公開する場合は tailscale serve を経由させること
launchd.user.agents.agent-deck-web = {
serviceConfig = {
ProgramArguments = [
"/opt/homebrew/bin/agent-deck"
"web"
"--no-tui"
"--listen"
"127.0.0.1:8420"
];
RunAtLoad = true;
KeepAlive = true;
StandardOutPath = "/Users/keito/Library/Logs/agent-deck-web.log";
StandardErrorPath = "/Users/keito/Library/Logs/agent-deck-web.err.log";
EnvironmentVariables = {
# claude/codex (~/.local/bin, ~/.bin)・node/gh (nix profile)・agent-deck (homebrew) を解決できる PATH
PATH = "/Users/keito/.local/bin:/Users/keito/.bin:/opt/homebrew/bin:/etc/profiles/per-user/keito/bin:/run/current-system/sw/bin:/usr/local/bin:/usr/bin:/bin";
};
};
};

# Shells
programs.zsh.enable = true;
}
13 changes: 11 additions & 2 deletions script/credentials.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ set -euo pipefail
SCRIPT_DIR="${0:A:h}"
REPO_ROOT="${SCRIPT_DIR:h}"
CREDENTIALS_DIR="$REPO_ROOT/credentials"
# テンプレート(op:// の vault/item 名を含む)は private-config 側を優先する
DEFAULT_PRIVATE_TEMPLATES="$HOME/develop/github.com/keito4/private-config/credentials/templates"
if [[ -z "${CREDENTIALS_TEMPLATES_DIR:-}" ]]; then
if [[ -d "$DEFAULT_PRIVATE_TEMPLATES" ]]; then
CREDENTIALS_TEMPLATES_DIR="$DEFAULT_PRIVATE_TEMPLATES"
else
CREDENTIALS_TEMPLATES_DIR="$CREDENTIALS_DIR/templates"
fi
fi
CREDENTIAL_PROVIDER="${CREDENTIAL_PROVIDER:-op}"
# Built-in provider: script/credentials/providers/op.sh
PROVIDER_PATH="$SCRIPT_DIR/credentials/providers/${CREDENTIAL_PROVIDER}.sh"
Expand Down Expand Up @@ -70,7 +79,7 @@ inject_template() {
fetch_all_credentials() {
echo "Fetching all credentials via provider ($(provider_name))..."

for template in "$CREDENTIALS_DIR"/templates/*.env.template; do
for template in "$CREDENTIALS_TEMPLATES_DIR"/*.env.template(N); do
if [[ -f "$template" ]]; then
local basename
basename=$(basename "$template" .env.template)
Expand All @@ -90,7 +99,7 @@ list_templates() {
echo "Available credential templates:"
echo

for template in "$CREDENTIALS_DIR"/templates/*.env.template; do
for template in "$CREDENTIALS_TEMPLATES_DIR"/*.env.template(N); do
if [[ -f "$template" ]]; then
local basename
basename=$(basename "$template" .env.template)
Expand Down
9 changes: 7 additions & 2 deletions test/integration/credentials_templates.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ extract_mcp_env_vars() {
}

@test "MCP credential template covers configured and documented environment variables" {
local template="$REPO_ROOT/credentials/templates/mcp.env.template"
# テンプレート(op:// の vault/item 名を含む)は keito4/private-config で管理する。
# CI など private-config が無い環境ではスキップし、ローカルでのみ整合性を検証する。
local templates_dir="${CREDENTIALS_TEMPLATES_DIR:-$HOME/develop/github.com/keito4/private-config/credentials/templates}"
local template="$templates_dir/mcp.env.template"
local readme="$REPO_ROOT/credentials/README.md"
local referenced_vars
local optional_vars=(N8N_API_URL N8N_API_KEY)
local var

assert_file_exists "$template"
if [ ! -f "$template" ]; then
skip "credentials templates are managed in keito4/private-config (not available here)"
fi
assert_file_exists "$readme"
! grep -q "setup-env.sh\\|setup-mcp.sh" "$template"

Expand Down
5 changes: 3 additions & 2 deletions test/nix-darwin-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ describe('nix-darwin and home-manager macOS configuration', () => {
[
'dot/aerospace.toml',
'dot/config/act/actrc',
'dot/config/agent-deck/config.toml',
'dot/config/codespaces-secrets/repos.txt',
'dot/config/graphite/aliases',
'git/gitignore',
'dot/.peco/config.json',
Expand All @@ -166,6 +164,9 @@ describe('nix-darwin and home-manager macOS configuration', () => {
expect(dotfilesModule).toContain('managedSource');
expect(dotfilesModule).toContain('".aerospace.toml"');
expect(dotfilesModule).toContain('".config/act/actrc"');
// 組織情報を含む設定は keito4/private-config から out-of-store symlink で参照する
expect(dotfilesModule).toContain('privateConfig');
expect(dotfilesModule).toContain('mkOutOfStoreSymlink');
expect(dotfilesModule).toContain('".config/agent-deck/config.toml"');
expect(dotfilesModule).toContain('".config/codespaces-secrets/repos.txt"');
expect(dotfilesModule).toContain('".config/graphite/aliases"');
Expand Down
Loading