Skip to content

Commit e1f5ef9

Browse files
committed
refactor: simplify config
1 parent 8383b7f commit e1f5ef9

File tree

8 files changed

+33
-94
lines changed

8 files changed

+33
-94
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,14 @@ refactoring guidance.
5353
## Running through Coze OpenAPI
5454
1. Set .env file for configuration on ABCoder's working directory. Taking Coze as an example:
5555
```
56-
# Base directory for other XXX_DIRs, default to current directory
57-
WORK_DIR=./
56+
# cache for repo,AST and so on
57+
WORK_DIR=tmp_abcoder
5858
59-
# DIRs below support both relative and absolute paths, and relative paths are relative to WORK_DIR
60-
REPO_DIR=tmp_repos
61-
CACHE_DIR=tmp_caches
62-
TOOLS_DIR=tools
63-
EXCLUDE_DIRS=target,gen-codes
59+
# exclude dirs for repo parsing, separated by comma
60+
EXCLUDE_DIRS=target,gen-codes
6461
65-
# coze|ollama
66-
API_TYPE=coze
62+
# LLM's api type
63+
API_TYPE=coze # coze|ollama
6764
6865
# LLM's output language
6966
LANGUAGE=zh
@@ -89,6 +86,10 @@ cargo run --bin cmd compress https://xxx.git
8986
3. Call the LLM to compress the repository codes, and refresh the AST for each call.
9087
You can stop the process at anytime after step 2. You can restart the compressing by running the same command.
9188

89+
5. Export the compressed results
90+
```
91+
cargo run --bin cmd export https://xxx.git --out-dir {OUTPUT_DIR}
92+
9293
# Status Update
9394
9495
The system is designed to automatically fetch the latest data from Github upon triggering relevant tasks, ensuring the

src/bin/cmd.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ fn main() {
5151
}
5252

5353
const USAGE: &str = "Usage: ABCoder <Action> <RepoPath> [Flags]
54-
Actions:
54+
RepoPath: the path of the repo to compress. Can be a local path or a git url.
55+
Actions: compress|export
5556
compress: compress the repo. Including flags:
5657
--parse-only: only parse the repo, not compress it
5758
--export-compress: export the compress result
@@ -60,7 +61,7 @@ compress: compress the repo. Including flags:
6061
--no-need-comment: not need comment in symbol content (only works for Go now)
6162
export: export the compress result to csv or markdown (default). Including flags:
6263
--csv: export the compress result to csv
63-
--out-dir <path>: output directory path, default is current directory
64+
--out-dir <path>: output directory path, default is $WORK_DIR
6465
--public-only: only export the public symbols
6566
";
6667

src/compress/llm/maas.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Copyright 2025 CloudWeGo Authors
2-
//
2+
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
55
// You may obtain a copy of the License at
6-
//
6+
//
77
// https://www.apache.org/licenses/LICENSE-2.0
8-
//
8+
//
99
// Unless required by applicable law or agreed to in writing, software
1010
// distributed under the License is distributed on an "AS IS" BASIS,
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,7 +24,7 @@ pub fn maas_compress_py(to_compress: &ToCompress, model_name: &str) -> String {
2424
use std::process::{Command, Stdio};
2525

2626
let command = "python3";
27-
let path = format!("{}/maas/model_call.py", &CONFIG.tools_dir);
27+
let path = format!("{}/maas/model_call.py", &CONFIG.work_dir);
2828
println!("executing command: {} {} {}", command, path, model_name);
2929

3030
// Create a new command process with piped stdin

src/config/mod.rs

Lines changed: 6 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,10 @@ pub enum Language {
2828
#[derive(Debug)]
2929
pub struct Config {
3030
pub work_dir: String,
31-
pub repo_dir: String,
32-
pub cache_dir: String,
3331
pub parser_dir: String,
3432
pub api_type: String,
3533
pub maas_model_name: String,
3634
pub mass_http_url: String,
37-
pub tools_dir: String,
3835

3936
pub coze_api_token: Option<String>,
4037
pub coze_bot_id: Option<String>,
@@ -46,23 +43,7 @@ pub struct Config {
4643
}
4744

4845
fn default_work_dir() -> String {
49-
std::env::current_dir()
50-
.unwrap()
51-
.to_str()
52-
.unwrap()
53-
.to_string()
54-
}
55-
56-
fn default_repo_dir() -> String {
57-
"tmp_repos".to_string()
58-
}
59-
60-
fn default_tools_dir() -> String {
61-
"tools".to_string()
62-
}
63-
64-
fn default_cache_dir() -> String {
65-
"tmp_caches".to_string()
46+
"tmp_abcoder".to_string()
6647
}
6748

6849
fn default_parser_dir() -> String {
@@ -81,11 +62,8 @@ impl Config {
8162
pub fn new() -> Self {
8263
Self {
8364
work_dir: default_work_dir(),
84-
repo_dir: default_repo_dir(),
85-
cache_dir: default_cache_dir(),
8665
parser_dir: default_parser_dir(),
8766
api_type: default_api_type(),
88-
tools_dir: default_tools_dir(),
8967
maas_model_name: default_maas_model_name(),
9068
mass_http_url: "".to_string(),
9169
coze_api_token: None,
@@ -97,13 +75,10 @@ impl Config {
9775
}
9876

9977
pub fn parse_from_env() -> Self {
100-
let mut s = Self {
78+
let s = Self {
10179
work_dir: std::env::var("WORK_DIR").unwrap_or_else(|_| default_work_dir()),
102-
repo_dir: std::env::var("REPO_DIR").unwrap_or_else(|_| default_repo_dir()),
103-
cache_dir: std::env::var("CACHE_DIR").unwrap_or_else(|_| default_cache_dir()),
10480
parser_dir: std::env::var("PARSER_DIR").unwrap_or_else(|_| default_parser_dir()),
10581
api_type: std::env::var("API_TYPE").unwrap_or_else(|_| default_api_type()),
106-
tools_dir: std::env::var("TOOLS_DIR").unwrap_or_else(|_| default_tools_dir()),
10782
maas_model_name: std::env::var("MAAS_MODEL_NAME")
10883
.unwrap_or_else(|_| default_maas_model_name()),
10984
mass_http_url: std::env::var("MASS_HTTP_URL").unwrap_or_else(|_| "".to_string()),
@@ -121,35 +96,6 @@ impl Config {
12196
})
12297
.unwrap_or(Language::Chinese),
12398
};
124-
125-
if !s.repo_dir.starts_with("/") {
126-
s.repo_dir = Path::new(&s.work_dir)
127-
.join(s.repo_dir)
128-
.to_str()
129-
.unwrap()
130-
.to_string();
131-
}
132-
if !s.cache_dir.starts_with("/") {
133-
s.cache_dir = Path::new(&s.work_dir)
134-
.join(s.cache_dir)
135-
.to_str()
136-
.unwrap()
137-
.to_string();
138-
}
139-
if !s.parser_dir.starts_with("/") {
140-
s.parser_dir = Path::new(&s.work_dir)
141-
.join(s.parser_dir)
142-
.to_str()
143-
.unwrap()
144-
.to_string();
145-
}
146-
if !s.tools_dir.starts_with("/") {
147-
s.tools_dir = Path::new(&s.work_dir)
148-
.join(s.tools_dir)
149-
.to_str()
150-
.unwrap()
151-
.to_string();
152-
}
15399
s
154100
}
155101
}
@@ -161,18 +107,8 @@ lazy_static! {
161107
};
162108
}
163109

164-
pub fn go_ast_path() -> String {
165-
Path::new(&CONFIG.tools_dir)
166-
.join("parser")
167-
.join("go_ast")
168-
.to_str()
169-
.unwrap()
170-
.to_string()
171-
}
172-
173-
pub fn rust_ast_path() -> String {
174-
Path::new(&CONFIG.tools_dir)
175-
.join("parser")
110+
pub fn parser_path() -> String {
111+
Path::new(&CONFIG.parser_dir)
176112
.join("lang")
177113
.to_str()
178114
.unwrap()
@@ -223,7 +159,8 @@ pub fn parser_and_args<'a>(
223159
opts: &parse::CompressOptions,
224160
) -> (String, Vec<String>) {
225161
let lang = decide_language(repo_path);
226-
let path = rust_ast_path();
162+
let path = parser_path();
163+
println!("parser path: {:?}", path);
227164
let mut args = vec![
228165
"collect".to_string(),
229166
lang.to_string(),

src/export.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ pub fn export_repo(repo: &Repository, opts: &ExportOptions) {
256256
Path::new(path)
257257
} else {
258258
// pwd
259-
Path::new(".")
259+
Path::new(&CONFIG.work_dir)
260260
};
261261

262262
if opts.csv {

src/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub fn force_parse_repo(repo_path: &String, opts: &CompressOptions) -> Result<Re
4141
}
4242

4343
fn parse_repo_path(repo_path: &String) -> Result<PathBuf, Error> {
44-
let git_dir = Path::new(CONFIG.repo_dir.as_str());
44+
let git_dir = Path::new(CONFIG.work_dir.as_str());
4545

4646
let ps: Vec<&str> = repo_path.split('/').collect();
4747
let path = if repo_path.ends_with(".git") || repo_path.starts_with("https://") {

src/storage/cache.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Copyright 2025 CloudWeGo Authors
2-
//
2+
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
55
// You may obtain a copy of the License at
6-
//
6+
//
77
// https://www.apache.org/licenses/LICENSE-2.0
8-
//
8+
//
99
// Unless required by applicable law or agreed to in writing, software
1010
// distributed under the License is distributed on an "AS IS" BASIS,
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -59,7 +59,7 @@ impl<C: StorageEngine, B: StorageEngine> StorageEngine for CachingStorageEngine<
5959

6060
pub fn get_cache() -> Box<dyn StorageEngine> {
6161
let mem = MemoryCache::new(12);
62-
let fs = FileStorage::new(Path::new(CONFIG.cache_dir.as_str())).unwrap();
62+
let fs = FileStorage::new(Path::new(CONFIG.work_dir.as_str())).unwrap();
6363

6464
let mut cache = CachingStorageEngine::new(mem, fs);
6565
return Box::new(cache);

src/utils/files.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Copyright 2025 CloudWeGo Authors
2-
//
2+
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
55
// You may obtain a copy of the License at
6-
//
6+
//
77
// https://www.apache.org/licenses/LICENSE-2.0
8-
//
8+
//
99
// Unless required by applicable law or agreed to in writing, software
1010
// distributed under the License is distributed on an "AS IS" BASIS,
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -69,7 +69,7 @@ impl fmt::Display for Node {
6969
for _ in 0..depth {
7070
write!(f, " ")?;
7171
}
72-
let display_name = node.name.trim_start_matches(&CONFIG.repo_dir);
72+
let display_name = node.name.trim_start_matches(&CONFIG.work_dir);
7373
writeln!(f, "└──{}", display_name)?;
7474

7575
for child in &node.children {

0 commit comments

Comments
 (0)