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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
set(ACECODE_WEB_DIST "${CMAKE_SOURCE_DIR}/web/dist")
set(ACECODE_WEB_EMBED_DIR "${ACECODE_WEB_DIST}")
if(NOT EXISTS "${ACECODE_WEB_DIST}")
message(WARNING

Check warning on line 98 in CMakeLists.txt

View workflow job for this annotation

GitHub Actions / unit-tests (linux-x64)

[acecode] web/dist/ not found — embedding a minimal fallback page. Run
"[acecode] web/dist/ not found — embedding a minimal fallback page. "
"Run `pnpm install && pnpm build` inside web/ before re-configuring for the full UI.")
set(ACECODE_WEB_EMBED_DIR "${CMAKE_BINARY_DIR}/generated/web-dist-fallback")
Expand Down Expand Up @@ -198,6 +198,7 @@
${CMAKE_SOURCE_DIR}/src/desktop/startup_progress.cpp
${CMAKE_SOURCE_DIR}/src/desktop/strings.cpp
${CMAKE_SOURCE_DIR}/src/desktop/workspace_registry.cpp
${CMAKE_SOURCE_DIR}/src/utils/append_file.cpp
${CMAKE_SOURCE_DIR}/src/utils/clipboard.cpp
${CMAKE_SOURCE_DIR}/src/utils/cwd_hash.cpp
${CMAKE_SOURCE_DIR}/src/utils/encoding.cpp
Expand Down
8 changes: 8 additions & 0 deletions docs/adr/0002-feedback-origin-log-boundary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Feedback packages include only their originating surface log

TUI feedback includes the latest TUI surface log, while GUI/Desktop feedback includes the latest Desktop surface log; neither includes the other surface's log. This keeps diagnostic attachments relevant to the reporting surface and avoids unnecessarily sending diagnostics from an unrelated interface.

## 术语

- **Feedback origin(反馈来源)**:发起诊断反馈包的运行界面。终端命令使用 `tui`,GUI/Desktop 接口使用 `desktop`;避免用 Feedback client 或 UI type 混淆运行界面与客户端。
- **Surface log(界面运行日志)**:某个运行界面在有效数据目录的 `logs` 子目录中生成的按日期日志,文件名使用该界面的前缀;避免称作 Shared UI log 或 Workspace log。
13 changes: 7 additions & 6 deletions docs/daemon-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3796,12 +3796,13 @@ Body fields are optional strings:
}
```

The package always carries the newest rotated log of every runtime that writes
into the logs directory: the desktop shell (`desktop-<date>.log`) and the daemon
that serves the request (`daemon-<date>.log`). Each is truncated to its last
512 KiB and stored as `logs/desktop.log.tail.txt` / `logs/daemon.log.tail.txt`.
A runtime with no log file present is skipped silently, so a browser-only
deployment uploads the daemon log alone. Upgrade diagnostics
The package carries the newest rotated Desktop shell log (`desktop-<date>.log`)
and the daemon log (`daemon-<date>.log`) that serves the request. Each is
truncated to its last 512 KiB and stored as `logs/desktop.log.tail.txt` /
`logs/daemon.log.tail.txt`. A runtime with no log file present is skipped
silently, so a browser-only deployment uploads the daemon log alone. Desktop
feedback does not attach `tui-<date>.log`; terminal `/feedback` instead carries
`tui-<date>.log` plus the daemon log and does not attach the Desktop log. Upgrade diagnostics
(`upgrade-<date>-<pid>.log`, one file per process) are handled as a window
rather than a single newest file: every upgrade log modified within the last
three days (72 hours) is merged oldest-first into `logs/upgrade.log.tail.txt`,
Expand Down
13 changes: 9 additions & 4 deletions docs/user-manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ acecode 启动时按 transport 连接每个配置的 MCP 服务器:
[MCP] Connected 2 server(s), registered 8 external tool(s).
```

若某个服务器连接失败,可在当前工作目录的 `acecode.log` 中查看详细错误信息。
若某个服务器连接失败,可在 `<数据目录>/logs/tui-YYYY-MM-DD.log` 中查看详细错误信息(默认数据目录为 `~/.acecode`)

### 管理 MCP 连接

Expand Down Expand Up @@ -856,9 +856,14 @@ OpenAI 兼容网关或 Anthropic 模型如果推理时间很长、连接容易

### Q: 日志文件在哪里?

acecode 运行时会在当前工作目录生成 `acecode.log` 文件,记录详细的调试信息。
Daemon 模式下不再写 `acecode.log`,而是按日期滚动写到
`<数据目录>/logs/daemon-{YYYY-MM-DD}.log`(详见第 16 章)。
普通 TUI 运行时会按本地日期滚动写入
`<数据目录>/logs/tui-YYYY-MM-DD.log`,记录详细的调试信息。默认数据目录为
`~/.acecode`;若已配置数据目录重定向,则使用重定向后的目录。已有工作区中的
`acecode.log` 会被保留,但新的 TUI 不再创建或追加该文件。启用 TUI 输入追踪的
调试构建会将高频鼠标和选区记录另写到
`<数据目录>/logs/tui-input-trace-YYYY-MM-DD.log`,同样不会写入工作区。

Daemon 模式按日期滚动写到 `<数据目录>/logs/daemon-YYYY-MM-DD.log`(详见第 16 章)。

---

Expand Down
2 changes: 1 addition & 1 deletion external/ftxui
2 changes: 2 additions & 0 deletions openspec/changes/centralize-tui-logs/.openspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-09-18
97 changes: 97 additions & 0 deletions openspec/changes/centralize-tui-logs/design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Design: centralize-tui-logs

## Context

The normal interactive startup path calls a file-static `initialize_logger_for_working_dir()` in `src/main.cpp`. It selects `Logger::init(working_dir + "/acecode.log")`, the legacy single-file mode. That explicit choice, rather than a logger fallback, causes project-local logs. `src/tui/tui_init.cpp` contains a duplicate helper with the same legacy behavior, although the current main path uses the file-static copy.

`Logger::init_with_rotation(get_logs_dir(), base_name, mirror_stderr)` is already used by desktop (`desktop`), daemon (`daemon`), and headless (`headless`). It creates the directory, names files `<base>-YYYY-MM-DD.log`, and reopens a new file when the local date changes. `get_logs_dir()` resolves from `get_acecode_dir()`, preserving the application-wide user/service data-root behavior.

TUI `/feedback` separately adds `ctx.cwd/acecode.log`, while the shared runtime-log collector finds desktop and daemon logs for GUI/Desktop feedback. The selected feedback boundary is origin-aware: TUI feedback must attach the centralized TUI log and must not attach Desktop logs; GUI/Desktop feedback must retain Desktop and daemon logs but must not attach TUI logs. This must move with the primary logger so TUI diagnostics remain attached after centralization.

## Goals / Non-Goals

**Goals:**

- Make normal interactive TUI runtime logs follow the same centralized data-directory convention as other runtime surfaces.
- Keep TUI records separate from desktop, daemon, and headless records via a `tui` filename prefix.
- Preserve legacy workspace files without filesystem migration or deletion.
- Ensure each feedback package contains its own surface log but not an unrelated interface's surface log.
- Keep the change localized, testable, and independent of frontend surfaces.

**Non-Goals:**

- Do not change the logger's legacy `init(file)` API; tests or specialized callers may still use it.
- Do not change which input events the opt-in `ACECODE_TUI_INPUT_TRACE` instrumentation records or its trace message format.
- Do not add retention, compression, or a user-configurable logging directory.
- Do not merge TUI logs with desktop or daemon logs.

## Decisions

### D1. Use the existing rotated logger with the `tui` base name

Both TUI logger initialization helpers will use:

```cpp
Logger::instance().init_with_rotation(get_logs_dir(), "tui", false);
```

This gives TUI logs the path `<data-dir>/logs/tui-YYYY-MM-DD.log`, automatically creates the directory, rotates at local midnight, and retains the current behavior of not writing log records to stderr. `working_dir` remains useful for the startup log message and later workspace setup, but no longer determines the log file path.

**Alternative considered:** keep a fixed `<data-dir>/logs/acecode.log`. Rejected because the existing runtime convention is per-surface dated files, and a TUI-specific prefix keeps simultaneous surfaces diagnosable.

### D2. Reconcile the duplicated TUI initialization helpers

The implementation must prevent `src/main.cpp` and `src/tui/tui_init.cpp` from continuing to encode divergent logger destinations. Prefer one shared TUI initialization helper when its existing dependency boundaries permit it; otherwise update both helpers to the same centralized rotated initialization and retain a focused regression test for the active startup seam.

The work must not leave a future path capable of silently restoring workspace-local primary logs.

### D3. Make runtime-log discovery feedback-origin-aware

Keep the existing GUI/Desktop runtime-log collector limited to `desktop` and `daemon`, preserving its documented REST contract. Add a TUI-specific collector (or an equivalent explicit source selector) that returns the latest `tui-YYYY-MM-DD.log` as `logs/tui.log.tail.txt` together with the daemon log, but excludes the Desktop log. Remove the TUI command's bespoke `ctx.cwd/acecode.log` source.

Both selectors use `latest_rotated_log_path` so matching and newest-file rules remain centralized. Missing logs remain non-fatal. This yields two explicit source sets:

- TUI `/feedback`: TUI + daemon + recent upgrade diagnostics.
- GUI/Desktop feedback: Desktop + daemon + recent upgrade diagnostics.

**Alternative considered:** add `tui` to `collect_runtime_log_sources(logs_dir)`. Rejected because that shared function backs the GUI/Desktop REST endpoint; it would silently broaden GUI diagnostic collection with unrelated terminal logs. Another alternative was a bespoke TUI path lookup in the command; rejected because it duplicates date-file matching and latest-file selection.

### D4. Configure FTXUI tracing through the process environment

FTXUI is built as a vcpkg dependency and cannot depend directly on ACECode's C++ configuration helpers. Add a dedicated environment variable, set by interactive TUI startup before FTXUI processes input, whose value is the UTF-8 absolute logs directory. FTXUI's trace writer reads that directory and creates/appends `tui-input-trace-YYYY-MM-DD.log` for the current local date on each trace write. If the variable is absent or the target file cannot be opened, tracing remains best-effort and creates no relative fallback file.

This preserves a clear dependency boundary: ACECode owns effective data-directory resolution, while FTXUI owns only local-date filename generation and appending trace records below the explicitly supplied directory. The trace writer should create the target directory before opening its file. An explicit absolute directory prevents worktree cwd changes from affecting the destination.

**Alternative considered:** link FTXUI against ACECode's logger/configuration utilities. Rejected because the dependency direction reverses the build boundary and would make the reusable FTXUI target depend on the application. Another alternative was a compile-time path definition; rejected because the effective data directory may be redirected at runtime and the date changes while a TUI process remains open.

### D5. Bump the FTXUI overlay port version

The overlay port builds `external/ftxui` from `SOURCE_PATH`, but vcpkg's ABI does not hash that source tree. Increment `ports/ftxui/vcpkg.json` `port-version` whenever the FTXUI source changes, ensuring existing local builds and CI rebuild the patched static library rather than reusing one that still writes `acecode.log` in the cwd.

### D6. Document the effective data-directory placeholder

Update the user manual's FAQ and MCP troubleshooting text to use `<数据目录>/logs/tui-YYYY-MM-DD.log`. Document the input-trace file separately as an opt-in debug artifact. Both descriptions use the effective data directory, which is accurate across supported platforms and data-root redirection, unlike hardcoding a Windows-only home path.

## Risks / Trade-offs

### PR 审核补充:Unicode 路径与多进程写入

Windows 创建目录与打开日志统一从 UTF-8 转换到原生路径,避免首次启动在中文数据目录创建乱码目录。集中日志允许多个工作区的 TUI 同时写入,因此不能用进程内互斥锁保护 CRT 的 seek-to-end + write:主日志使用独立的低层追加文件模块,Windows 以 `FILE_APPEND_DATA` 打开并整条 `WriteFile`,POSIX 以 `O_APPEND` 打开并整条 `write`。FTXUI 在其自身依赖边界内使用同样的系统语义,保持追踪记录格式。拒绝相对追踪目录;打开失败时维持静默 best-effort,不写工作区备用文件。

回归验证包含独立进程同时写同一文件、中文路径首次创建及无法打开的目标。操作系统报告短写或磁盘错误时不把残余片段另行追加,以免把一条记录拆散穿插到其他进程记录中;这些错误仍按既有日志 best-effort 语义处理。

- **Feedback archive name change:** consumers that recognize `logs/acecode.log.tail.txt` will no longer see a TUI legacy entry. The old file was workspace-specific and is no longer a valid runtime source; a distinct `logs/tui.log.tail.txt` accurately identifies the new source. The high-volume FTXUI input trace remains a local diagnostic artifact and is not attached by either feedback origin.
- **Startup ordering:** TUI logger initialization remains before normal configuration loading, as it is today. `get_logs_dir()` only uses existing data-directory resolution and does not require loaded application configuration.
- **Old docs and external scripts:** workspace-local `acecode.log` may be referenced externally. The selected migration policy intentionally preserves old files but does not maintain an active compatibility copy, preventing further workspace pollution.

## Migration Plan

On the first upgraded interactive TUI launch, ACECode writes to the centralized dated TUI file. Existing workspace `acecode.log` files are untouched. `/feedback` begins attaching the latest centralized TUI log when available. No configuration or session migration is required.

## Validation

- Unit-test logger rotation behavior using the established `Logger` test fixture and add a targeted assertion for `tui` file naming.
- Unit-test feedback runtime source discovery with TUI, desktop, and daemon files, including latest-file selection and missing-TUI behavior.
- Add or adjust a focused TUI startup helper test so the production initialization chooses `get_logs_dir()` and the `tui` base name without needing an interactive terminal.
- Run the focused native tests and the repository's relevant build target.
- Verify documentation contains no remaining normal-TUI instructions to inspect workspace-local `acecode.log`.
34 changes: 34 additions & 0 deletions openspec/changes/centralize-tui-logs/proposal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Proposal: centralize-tui-logs

## Why

Interactive TUI startup currently writes a non-rotating `acecode.log` into the active workspace. This pollutes project directories, including startup worktrees, and differs from Desktop, daemon, and headless modes, which write dated logs in the ACECode data directory. The TUI feedback command also packages the workspace-local file, so it would omit the relevant diagnostics after the logging destination changes unless its source is updated together.

## What Changes

- Move the interactive TUI primary logger from `<workspace>/acecode.log` to `<data-dir>/logs/tui-YYYY-MM-DD.log`.
- Reuse the existing rotating logger behavior: create the shared logs directory as needed, rotate at local midnight, and do not mirror TUI records to stderr.
- Preserve existing workspace `acecode.log` files without migrating or deleting them; future normal TUI runs no longer create or append to them.
- Change TUI `/feedback` to attach the latest rotated TUI log as `logs/tui.log.tail.txt` instead of attaching `<workspace>/acecode.log`; it continues to attach the daemon and recent upgrade diagnostics but no longer attaches Desktop logs.
- Keep GUI/Desktop feedback limited to Desktop, daemon, and recent upgrade diagnostics; it must not attach TUI logs.
- Move opt-in FTXUI input tracing from a relative `acecode.log` in the active workspace to an independent centralized daily file, `<data-dir>/logs/tui-input-trace-YYYY-MM-DD.log`.
- Update user documentation and test coverage for the centralized TUI location and feedback source.

## Capabilities

### New Capabilities

- `tui-runtime-logging`: Centralized, dated TUI runtime logs and their feedback-package inclusion.

### Modified Capabilities

(None.)

## Impact

- **TUI startup:** `src/main.cpp` and the duplicate TUI logger initialization helper in `src/tui/tui_init.cpp`.
- **FTXUI input tracing:** `external/ftxui/src/ftxui/component/app.cpp`, its CMake definitions, and `ports/ftxui/` overlay-version metadata.
- **Feedback:** `src/commands/builtin_commands.cpp` and the rotated-log discovery helpers in `src/feedback/feedback_upload.*`.
- **Tests:** logger, feedback-package, and a focused TUI initialization seam if needed for testability.
- **Documentation:** `docs/user-manual.md`; update `docs/daemon-api.md` if its feedback attachment contract is expanded to name the TUI runtime log.
- **Compatibility:** existing FTXUI trace message format remains unchanged; only its output destination and daily rotation behavior change.
Loading
Loading