Skip to main content

j_cli/
constants.rs

1// 项目全局常量定义
2// 所有魔法字符串和可复用常量统一在此维护
3
4// ========== 版本信息 ==========
5
6/// 内核版本号(自动从 Cargo.toml 读取,编译时确定)
7pub const VERSION: &str = env!("CARGO_PKG_VERSION");
8
9/// 项目名称
10pub const APP_NAME: &str = "work-copilot";
11
12/// 作者
13pub const AUTHOR: &str = "lingojack";
14
15/// 邮箱
16pub const EMAIL: &str = "lingojack@qq.com";
17
18/// 配置编辑界面的字段列表
19pub const CONFIG_FIELDS: &[&str] = &["name", "api_base", "api_key", "model"];
20/// 全局配置字段
21pub const CONFIG_GLOBAL_FIELDS: &[&str] = &[
22    "system_prompt",
23    "stream_mode",
24    "max_history_messages",
25    "theme",
26    "tools_enabled",
27];
28
29/// Toast 通知显示时长(秒)
30pub const TOAST_DURATION_SECS: u64 = 4;
31
32// ========== Section 名称 ==========
33
34/// 配置文件中的 section 名称常量
35pub mod section {
36    pub const PATH: &str = "path";
37    pub const INNER_URL: &str = "inner_url";
38    pub const OUTER_URL: &str = "outer_url";
39    pub const EDITOR: &str = "editor";
40    pub const BROWSER: &str = "browser";
41    pub const VPN: &str = "vpn";
42    pub const SCRIPT: &str = "script";
43    pub const VERSION: &str = "version";
44    pub const SETTING: &str = "setting";
45    pub const LOG: &str = "log";
46    pub const REPORT: &str = "report";
47}
48
49/// 所有 section 名称列表(有序)
50pub const ALL_SECTIONS: &[&str] = &[
51    section::PATH,
52    section::INNER_URL,
53    section::OUTER_URL,
54    section::EDITOR,
55    section::BROWSER,
56    section::VPN,
57    section::SCRIPT,
58    section::VERSION,
59    section::SETTING,
60    section::LOG,
61    section::REPORT,
62];
63
64/// 默认展示的 section(ls 命令无参数时使用)
65pub const DEFAULT_DISPLAY_SECTIONS: &[&str] = &[
66    section::PATH,
67    section::INNER_URL,
68    section::OUTER_URL,
69    section::EDITOR,
70    section::BROWSER,
71    section::VPN,
72    section::SCRIPT,
73];
74
75/// contain 命令默认搜索的 section
76pub const CONTAIN_SEARCH_SECTIONS: &[&str] = &[
77    section::PATH,
78    section::SCRIPT,
79    section::BROWSER,
80    section::EDITOR,
81    section::VPN,
82    section::INNER_URL,
83    section::OUTER_URL,
84];
85
86// ========== 分类标记 ==========
87
88/// 可标记的分类列表(note/denote 命令使用)
89pub const NOTE_CATEGORIES: &[&str] = &[
90    section::BROWSER,
91    section::EDITOR,
92    section::VPN,
93    section::OUTER_URL,
94    section::SCRIPT,
95];
96
97// ========== 别名查找 section ==========
98
99/// 用于查找别名路径的 section 列表(按优先级排列)
100pub const ALIAS_PATH_SECTIONS: &[&str] = &[section::PATH, section::INNER_URL, section::OUTER_URL];
101
102/// 用于判断别名是否存在的 section 列表
103pub const ALIAS_EXISTS_SECTIONS: &[&str] = &[
104    section::PATH,
105    section::INNER_URL,
106    section::OUTER_URL,
107    section::SCRIPT,
108    section::BROWSER,
109    section::EDITOR,
110    section::VPN,
111];
112
113/// modify 命令需要检查并更新的 section 列表
114pub const MODIFY_SECTIONS: &[&str] = &[
115    section::PATH,
116    section::INNER_URL,
117    section::OUTER_URL,
118    section::EDITOR,
119    section::BROWSER,
120    section::VPN,
121];
122
123/// remove 时需要同步清理的 category section
124pub const REMOVE_CLEANUP_SECTIONS: &[&str] = &[
125    section::EDITOR,
126    section::VPN,
127    section::BROWSER,
128    section::SCRIPT,
129];
130
131/// rename 时需要同步重命名的 category section
132pub const RENAME_SYNC_SECTIONS: &[&str] = &[
133    section::BROWSER,
134    section::EDITOR,
135    section::VPN,
136    section::SCRIPT,
137];
138
139// ========== 配置 key ==========
140
141/// 配置 key 名称常量
142pub mod config_key {
143    pub const MODE: &str = "mode";
144    pub const VERBOSE: &str = "verbose";
145    pub const CONCISE: &str = "concise";
146    pub const SEARCH_ENGINE: &str = "search-engine";
147    pub const WEEK_REPORT: &str = "week_report";
148    pub const WEEK_NUM: &str = "week_num";
149    pub const LAST_DAY: &str = "last_day";
150    pub const GIT_REPO: &str = "git_repo";
151}
152
153// ========== 搜索引擎 ==========
154
155/// 默认搜索引擎
156pub const DEFAULT_SEARCH_ENGINE: &str = "bing";
157
158/// 搜索引擎 URL 模板
159pub mod search_engine {
160    pub const GOOGLE: &str = "https://www.google.com/search?q={}";
161    pub const BING: &str = "https://www.bing.com/search?q={}";
162    pub const BAIDU: &str = "https://www.baidu.com/s?wd={}";
163}
164
165// ========== 日报相关 ==========
166
167/// 日报日期格式
168pub const REPORT_DATE_FORMAT: &str = "%Y.%m.%d";
169
170/// 日报简短日期格式
171pub const REPORT_SIMPLE_DATE_FORMAT: &str = "%Y/%m/%d";
172
173/// check 命令默认行数
174pub const DEFAULT_CHECK_LINES: usize = 10;
175
176// ========== 命令名常量 ==========
177
178/// 所有内置命令的名称和别名,统一在此维护
179/// interactive.rs 的补全规则 / parse_interactive_command 和 command/mod.rs 的 all_command_keywords 共同引用
180pub mod cmd {
181    // 别名管理
182    pub const SET: &[&str] = &["set", "s"];
183    pub const REMOVE: &[&str] = &["rm", "remove"];
184    pub const RENAME: &[&str] = &["rename", "rn"];
185    pub const MODIFY: &[&str] = &["mf", "modify"];
186
187    // 分类标记
188    pub const NOTE: &[&str] = &["note", "nt"];
189    pub const DENOTE: &[&str] = &["denote", "dnt"];
190
191    // 列表 & 查找
192    pub const LIST: &[&str] = &["ls", "list"];
193    pub const CONTAIN: &[&str] = &["contain", "find"];
194
195    // 日报系统
196    pub const REPORT: &[&str] = &["report", "r"];
197    pub const REPORTCTL: &[&str] = &["reportctl", "rctl"];
198    pub const CHECK: &[&str] = &["check", "c"];
199    pub const SEARCH: &[&str] = &["search", "select", "look", "sch"];
200
201    // 待办备忘录
202    pub const TODO: &[&str] = &["todo", "td"];
203
204    // 脚本
205    pub const CONCAT: &[&str] = &["concat"];
206
207    // 倒计时
208    pub const TIME: &[&str] = &["time"];
209
210    // 系统设置
211    pub const LOG: &[&str] = &["log"];
212    pub const CHANGE: &[&str] = &["change", "chg"];
213    pub const CLEAR: &[&str] = &["clear", "cls"];
214
215    // 系统信息
216    pub const VERSION: &[&str] = &["version", "v"];
217    pub const HELP: &[&str] = &["help", "h"];
218    pub const EXIT: &[&str] = &["exit", "q", "quit"];
219
220    // shell 补全
221    pub const COMPLETION: &[&str] = &["completion"];
222
223    // AI 对话
224    pub const CHAT: &[&str] = &["chat", "ai"];
225
226    // 语音转文字
227    pub const VOICE: &[&str] = &["voice", "vc"];
228
229    // agent(预留)
230    pub const AGENT: &[&str] = &["agent"];
231    pub const SYSTEM: &[&str] = &["system", "ps"];
232
233    /// 获取所有内置命令关键字的扁平列表(用于判断别名冲突等)
234    pub fn all_keywords() -> Vec<&'static str> {
235        let groups: &[&[&str]] = &[
236            SET, REMOVE, RENAME, MODIFY, NOTE, DENOTE, LIST, CONTAIN, REPORT, REPORTCTL, CHECK,
237            SEARCH, TODO, CHAT, CONCAT, TIME, LOG, CHANGE, CLEAR, VERSION, HELP, EXIT, COMPLETION,
238            VOICE, AGENT, SYSTEM,
239        ];
240        groups.iter().flat_map(|g| g.iter().copied()).collect()
241    }
242}
243
244// ========== reportctl 子命令 ==========
245
246pub mod rmeta_action {
247    pub const NEW: &str = "new";
248    pub const SYNC: &str = "sync";
249    pub const PUSH: &str = "push";
250    pub const PULL: &str = "pull";
251    pub const SET_URL: &str = "set-url";
252    pub const OPEN: &str = "open";
253}
254
255// ========== time 子命令 ==========
256
257pub mod time_function {
258    pub const COUNTDOWN: &str = "countdown";
259}
260
261// ========== search 标记 ==========
262
263pub mod search_flag {
264    pub const FUZZY_SHORT: &str = "-f";
265    pub const FUZZY: &str = "-fuzzy";
266}
267
268// ========== ls 补全固定选项 ==========
269
270pub const LIST_ALL: &str = "all";
271
272// ========== 交互模式 ==========
273
274/// 欢迎语
275pub const WELCOME_MESSAGE: &str = "Welcome to use j-cli 🚀 ~";
276
277/// Shell 命令前缀字符
278pub const SHELL_PREFIX: char = '!';
279
280/// 交互模式提示符
281pub const INTERACTIVE_PROMPT: &str = "j >";
282
283/// 历史记录文件名
284pub const HISTORY_FILE: &str = "history.txt";
285
286/// 配置文件名
287pub const CONFIG_FILE: &str = "config.yaml";
288
289/// 脚本目录名
290pub const SCRIPTS_DIR: &str = "scripts";
291
292/// 日报目录名
293pub const REPORT_DIR: &str = "report";
294
295/// agent 目录名
296pub const AGENT_DIR: &str = "agent";
297
298/// agent 日志目录名
299pub const AGENT_LOG_DIR: &str = "logs";
300
301/// 日报默认文件名
302pub const REPORT_DEFAULT_FILE: &str = "week_report.md";
303
304/// 数据根目录名
305pub const DATA_DIR: &str = ".jdata";
306
307/// 数据路径环境变量名
308pub const DATA_PATH_ENV: &str = "J_DATA_PATH";
309
310// ========== Shell 命令 ==========
311
312// ========== 语音转文字 ==========
313
314/// 语音转文字相关常量
315pub mod voice {
316    /// 语音数据目录名
317    pub const VOICE_DIR: &str = "voice";
318    /// 模型子目录名
319    pub const MODEL_DIR: &str = "model";
320    /// 默认模型大小
321    pub const DEFAULT_MODEL: &str = "small";
322    /// 支持的模型大小列表
323    pub const MODEL_SIZES: &[&str] = &["tiny", "base", "small", "medium", "large"];
324    /// Whisper 模型下载 URL 模板 (Hugging Face)
325    pub const MODEL_URL_TEMPLATE: &str =
326        "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-{}.bin";
327    /// 模型文件名模板
328    pub const MODEL_FILE_TEMPLATE: &str = "ggml-{}.bin";
329    /// 录音采样率 (Whisper 要求 16kHz)
330    pub const SAMPLE_RATE: u32 = 16000;
331    /// voice 操作: 下载模型
332    pub const ACTION_DOWNLOAD: &str = "download";
333    /// 流式转写间隔(秒)
334    pub const STREAMING_INTERVAL_SECS: u64 = 3;
335    /// 最短有效音频长度(秒)
336    pub const MIN_AUDIO_SECS: u64 = 1;
337    /// 模型优先级(从高到低)
338    pub const MODEL_PRIORITY: &[&str] = &["large", "medium", "small", "base", "tiny"];
339}
340
341pub mod shell {
342    pub const BASH_PATH: &str = "/bin/bash";
343    pub const WINDOWS_CMD: &str = "cmd";
344    pub const WINDOWS_CMD_FLAG: &str = "/c";
345    pub const BASH_CMD_FLAG: &str = "-c";
346    pub const WINDOWS_OS: &str = "windows";
347    pub const MACOS_OS: &str = "macos";
348}
349
350// ========== Todo 过滤状态 ==========
351
352/// Todo 过滤模式常量
353pub mod todo_filter {
354    /// 显示全部待办项
355    pub const ALL: usize = 0;
356    /// 只显示未完成的待办项
357    pub const UNDONE: usize = 1;
358    /// 只显示已完成的待办项
359    pub const DONE: usize = 2;
360    /// 过滤模式总数
361    pub const COUNT: usize = 3;
362
363    /// 获取过滤模式标签
364    pub fn label(filter: usize) -> &'static str {
365        match filter {
366            UNDONE => "未完成",
367            DONE => "已完成",
368            _ => "全部",
369        }
370    }
371
372    /// 默认过滤模式(未完成)
373    pub const DEFAULT: usize = UNDONE;
374}