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