-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpaths.hpp
More file actions
77 lines (63 loc) · 3.58 KB
/
Copy pathpaths.hpp
File metadata and controls
77 lines (63 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#pragma once
// 进程级 RunMode 抽象 + 跨平台数据目录解析(spec design.md Decision 8)。
//
// 目的: ServiceMain 入口需要在做任何文件 IO 之前把数据根从 ~/.acecode/ 切到
// 系统级位置(Windows ProgramData / macOS /Library/Application Support /
// Linux /var/lib),否则 LocalSystem 身份的 daemon 写的产物落在 systemprofile
// 下,TUI 看不见。User 模式(默认)行为与历史完全一致 — TUI 与 standalone
// daemon 不受影响。
//
// set_run_mode() 是 once-only — 二次调用打 LOG_WARN 后忽略;这是一道防呆,避免
// 进程半路改根目录把状态散到两套路径下。测试通过 override_run_mode_for_test()
// 绕过 once 保护,fixture TearDown 应调 reset_run_mode_for_test() 清场。
#include <string>
#include <vector>
namespace acecode {
// Expand ~ and ${ENV} style variables in a path string. Returns the expanded
// form; missing env vars are left as-is (per hermes convention).
std::string expand_path(const std::string& raw);
// Collect project-level directories from cwd up to (but not including) the
// user's home directory. Returned deepest-first so cwd-level skills take
// precedence over ancestor-level skills when scanned in order. HOME itself is
// excluded because the user-global skills root (`~/.acecode/skills`) is
// registered separately.
std::vector<std::string> get_project_dirs_up_to_home(const std::string& cwd);
enum class RunMode {
User = 0, // 默认 — TUI / standalone daemon / `acecode daemon --foreground`
Service = 1, // SCM ServiceMain 拉起的 worker
};
// 进程启动早期调一次。第二次起被吞掉(LOG_WARN 提示)。
void set_run_mode(RunMode mode);
// 当前进程的 RunMode(默认 User)。
RunMode get_run_mode();
// 纯函数: 算给定 mode 下的数据根目录(不创建目录,调用方自己 create_directories)。
//
// Windows | User : %USERPROFILE%\.acecode\ (USERPROFILE 缺失退到 HOMEDRIVE+HOMEPATH,再缺失退到 .\.acecode)
// | Service : %PROGRAMDATA%\acecode\ (≈ C:\ProgramData\acecode\,缺失退到字面 C:\ProgramData)
// macOS | User : $HOME/.acecode/ (缺失退到 ./.acecode)
// | Service : /Library/Application Support/acecode
// Linux | User : $HOME/.acecode/ (缺失退到 ./.acecode)
// | Service : /var/lib/acecode
std::string resolve_data_dir(RunMode mode);
// 进程级 run/ 目录覆盖。非空时 config::get_run_dir() 直接返回这个,而不再
// 用 <data_dir>/run/ 默认。
//
// 用途: desktop 多 workspace 模式下,每个 workspace 的 daemon 必须有独立的
// runtime files (heartbeat / pid / port / token / GUID lock),否则第一个 daemon
// 启动后 validate_can_start 会拒绝其它 workspace 的 daemon。daemon 的 cli
// 解析到 --run-dir=<path> 时在 worker 启动早期调本函数,把 run/ 切到
// ~/.acecode/projects/<workspace_hash>/run/。
//
// config / sessions / memory / logs 等其它子目录仍走 <data_dir>(共享),只
// 隔离 run/ — 这是修复孤儿 daemon 互锁问题的最小必要面。
//
// 空字符串 = 清除 override。线程安全(内部加锁)。
void set_run_dir_override(const std::string& path);
std::string get_run_dir_override();
// === 测试专用 helper(只在测试代码用,生产路径不应调) ===
// 直接覆盖当前 RunMode,绕过 once-only 保护;返回原值方便 test fixture 还原。
RunMode override_run_mode_for_test(RunMode mode);
// 把 RunMode 与 once-only 标记都重置回初始(User + 未 set 过)。
// fixture TearDown 调,确保测试间互不污染。
void reset_run_mode_for_test();
} // namespace acecode