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