Skip to content

feat(runtime): enhance PATH at startup for all downstream spawn sites#193

Merged
TCP404 merged 1 commit into
mainfrom
boii/feat/startup-path-enhance
May 8, 2026
Merged

feat(runtime): enhance PATH at startup for all downstream spawn sites#193
TCP404 merged 1 commit into
mainfrom
boii/feat/startup-path-enhance

Conversation

@TCP404

@TCP404 TCP404 commented May 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • 新增 `aionui-runtime::shell_env::enhance_process_path()` — 启动最早位置(tokio runtime 构造之前)调用一次,合并三层 PATH:bundled bun 目录 → 平台 extra bins (`/.bun/bin`, `/.cargo/bin`, `~/.local/bin`, Windows `%APPDATA%\npm`, Git, Scoop, …) → 当前 PATH → login-shell $PATH (Unix, 3s 超时)。之后所有下游 `which::which(...)` / `Command::new(...)` 自动受益。
  • 修复 v2 后端"从 launchd / Finder / Windows 快捷方式 / systemd service 启动时 PATH 几乎为空"的问题——这正是 v1 `shellEnv.ts` 解决的 pain point,v2 到目前为止完全没覆盖。
  • `aionui-app` 从 `#[tokio::main]` 改为手动构造 runtime,以满足 Rust 2024 `env::set_var` 的单线程前置条件。功能上等价于原 macro 展开(`new_multi_thread().enable_all()`)。
  • 合并使用 `std::env::split_paths` / `join_paths` 处理跨平台分隔符与 PathBuf 去重。Login shell 探测避免 pipe buffer 死锁(先 read 后 wait)。
  • tracing init 之后补一条结构化 `startup: PATH ready path_segments=N path_len=M` info 日志(不含完整 PATH 内容,避免泄漏用户目录)。

23 个现有 `Command::new` / `which::which` 调用点未改动——它们通过 `env::var("PATH")` 继承自动受益。

Test plan

  • `cargo test -p aionui-runtime` 全绿(29 unit + 2 integration;新增 10 个 shell_env 测试)
  • `cargo test -p aionui-app --lib` 全绿(12 passed)
  • `cargo clippy -p aionui-runtime -p aionui-app -- -D warnings` 无警告
  • `cargo fmt --all -- --check` 通过
  • Smoke: `AIONUI_LOG_LEVEL=info ./aionui-backend --data-dir /tmp/smoke` 打印 `startup: PATH ready path_segments=31 path_len=1323`
  • 手工验证: `SHELL=/bin/false cargo run` 应在 3s 内打 warn(login shell 超时)

Design & Plan

  • Spec: `docs/superpowers/specs/2026-05-08-startup-path-enhance-design.md`
  • Plan: `docs/superpowers/plans/2026-05-08-startup-path-enhance.md`

Follow-up

后续 PR (per Plan §Non-Goals / Follow-up):

  • PR B: `aionui-runtime::spawn::Builder` —— kill_on_drop + env 清理 + bun dir 前置;迁移 `aionui-ai-agent` spawn 站点
  • PR C+: 逐 crate 迁移 `aionui-mcp` / `aionui-office` / `aionui-extension` / `aionui-shell` 到 Spawn Builder

🤖 Generated with Claude Code

Adds aionui_runtime::shell_env::enhance_process_path(), invoked from
aionui-app's fn main() before the tokio runtime is constructed. It merges
three layers into the current process PATH:

1. Bundled bun directory (highest priority).
2. Platform extra bins: ~/.bun/bin, ~/.cargo/bin, ~/go/bin, ~/.deno/bin,
   ~/.local/bin, ~/.volta/bin. Windows adds %APPDATA%\npm,
   %LOCALAPPDATA%\pnpm, %LOCALAPPDATA%\fnm_multishells, Git cmd/bin,
   ProgramFiles\nodejs, %SCOOP%\shims.
3. Current PATH (inherited from the launching process).
4. Login-shell PATH (Unix only, 3s timeout) — fixes launchd / Finder /
   Windows-shortcut / systemd-service starts where the inherited PATH is
   nearly empty. Uses std::env::split_paths / join_paths and PathBuf
   dedup to be cross-platform correct.

All 23 existing Command::new / which::which sites across 6 crates
automatically inherit the enriched PATH — no per-site migration.

aionui-app switches from #[tokio::main] to a manual
tokio::runtime::Builder::new_multi_thread().enable_all() so we can run
the unsafe env::set_var call while single-threaded, as required by
Rust 2024.

A structured info log "startup: PATH ready path_segments=N path_len=M"
fires after tracing subscriber init, so the enhancement is observable
without logging the full PATH content.

Design:  docs/superpowers/specs/2026-05-08-startup-path-enhance-design.md
Plan:    docs/superpowers/plans/2026-05-08-startup-path-enhance.md
@TCP404 TCP404 force-pushed the boii/feat/startup-path-enhance branch from d245deb to 60c6521 Compare May 8, 2026 07:00
@TCP404 TCP404 merged commit 1e3e00e into main May 8, 2026
1 of 5 checks passed
@TCP404 TCP404 deleted the boii/feat/startup-path-enhance branch May 8, 2026 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant