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