Skip to content

Commit 8be29e4

Browse files
authored
feat: dynamically set AST version and tool version (#102)
* feat: support dynamic version * update UniAST field `ToolVersion` * feat:(ts) update uniast
1 parent 601fc8a commit 8be29e4

File tree

12 files changed

+86
-32
lines changed

12 files changed

+86
-32
lines changed

docs/uniast-en.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ A repository consists of entity Modules and relationship Graph
8181

8282
```json
8383
{
84-
"Identity": "/Users/bytedance/golang/work/abcoder/tmp/localsession",
84+
"id": "/Users/bytedance/golang/work/abcoder/tmp/localsession",
85+
"ASTVersion": "xx",
86+
"ToolVersion": "yy",
87+
"Path": "/a/b/localsession",
8588
"Modules": {
8689
"github.com/bytedance/gopkg@v0.0.0-20230728082804-614d0af6619b": {},
8790
"github.com/cloudwego/localsession": {}
@@ -90,7 +93,7 @@ A repository consists of entity Modules and relationship Graph
9093
}
9194
```
9295

93-
- Identity: The unique name of the repo. Since the abcoder parser does not currently retrieve repository git information, the absolute path where it is currently located is generally used as the Identity
96+
- id: The unique name of the repo. Since the abcoder parser does not currently retrieve repository git information, the absolute path where it is currently located is generally used as the Identity
9497

9598

9699
- Modules: Contains submodules, a dictionary of {ModPath}: {Module AST}. Both repository modules and external dependency modules can appear in Modules, but need to be distinguished by ModulePath.
@@ -104,7 +107,10 @@ A repository consists of entity Modules and relationship Graph
104107

105108
- Path: The file directory of the repository, usually should be an absolute path
106109

107-
- ASTVersion: The UniAST version used to parse
110+
- ASTVersion: The UniAST version spefication when the repository is parsed
111+
112+
- ToolVersion: The abcoder version used to parse
113+
108114

109115
### Module
110116

docs/uniast-zh.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ Universal Abstract-Syntax-Tree 是 ABCoder 建立的一种 LLM 亲和、语言
8181

8282
```json
8383
{
84-
"Identity": "/Users/bytedance/golang/work/abcoder/tmp/localsession",
84+
"id": "/Users/bytedance/golang/work/abcoder/tmp/localsession",
85+
"ASTVersion": "xx",
86+
"ToolVersion": "yy",
87+
"Path": "/a/b/localsession",
8588
"Modules": {
8689
"github.com/bytedance/gopkg@v0.0.0-20230728082804-614d0af6619b": {},
8790
"github.com/cloudwego/localsession": {}
@@ -90,7 +93,7 @@ Universal Abstract-Syntax-Tree 是 ABCoder 建立的一种 LLM 亲和、语言
9093
}
9194
```
9295

93-
- Identity: repo 的唯一名称。由于 abcoder parser 目前不获取仓库 git 信息,因此一般使用当前所处的绝对路径作为 Identity
96+
- id: repo 的唯一名称。由于 abcoder parser 目前不获取仓库 git 信息,因此一般使用当前所处的绝对路径作为 Identity
9497

9598

9699
- Modules: 包含的子模块,{ModPath} : {Module AST} 的字典,本仓库模块和外部依赖模块都可以出现在 Modules 中,但是需要通过 ModulePath 来区分。
@@ -104,7 +107,9 @@ Universal Abstract-Syntax-Tree 是 ABCoder 建立的一种 LLM 亲和、语言
104107

105108
- Path: 仓库的文件目录,通常应该为绝对路径
106109

107-
- ASTVersion: 解析时使用的 UniAST 版本
110+
- ASTVersion: 解析时对应的 UniAST 版本
111+
112+
- ToolVersion: 解析时使用的 abcoder 版本
108113

109114

110115
### Module

lang/parse.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/cloudwego/abcoder/lang/register"
3636
"github.com/cloudwego/abcoder/lang/rust"
3737
"github.com/cloudwego/abcoder/lang/uniast"
38+
"github.com/cloudwego/abcoder/version"
3839
)
3940

4041
// ParseOptions is the options for parsing the repo.
@@ -105,6 +106,7 @@ func Parse(ctx context.Context, uri string, args ParseOptions) ([]byte, error) {
105106
}
106107

107108
repo.ASTVersion = uniast.Version
109+
repo.ToolVersion = version.Version
108110

109111
out, err := json.Marshal(repo)
110112
if err != nil {

lang/uniast/ast.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@ type NodeGraph map[string]*Node
8383

8484
// Repository
8585
type Repository struct {
86-
ASTVersion string
87-
Name string `json:"id"` // module name
88-
Path string // repo path
89-
Modules map[string]*Module // module name => module
90-
Graph NodeGraph // node id => node
86+
Name string `json:"id"` // module name
87+
ASTVersion string // uniast version
88+
ToolVersion string // abcoder version
89+
Path string // repo absolute path
90+
Modules map[string]*Module // module name => module
91+
Graph NodeGraph // node id => node
9192
}
9293

9394
func (r Repository) ID() string {

lang/uniast/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616

1717
package uniast
1818

19-
const Version = "v0.1.3"
19+
const Version = "v0.1.4"

main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import (
4747
"github.com/cloudwego/abcoder/llm/agent"
4848
"github.com/cloudwego/abcoder/llm/mcp"
4949
"github.com/cloudwego/abcoder/llm/tool"
50+
"github.com/cloudwego/abcoder/version"
5051
)
5152

5253
const Usage = `abcoder <Action> [Language] <Path> [Flags]
@@ -106,7 +107,7 @@ func main() {
106107

107108
switch action {
108109
case "version":
109-
fmt.Fprintf(os.Stdout, "%s\n", Version)
110+
fmt.Fprintf(os.Stdout, "%s\n", version.Version)
110111

111112
case "parse":
112113
language, uri := parseArgsAndFlags(flags, true, flagHelp, flagVerbose)
@@ -183,7 +184,7 @@ func main() {
183184

184185
svr := mcp.NewServer(mcp.ServerOptions{
185186
ServerName: "abcoder",
186-
ServerVersion: Version,
187+
ServerVersion: version.Version,
187188
Verbose: *flagVerbose,
188189
ASTReadToolsOptions: tool.ASTReadToolsOptions{
189190
RepoASTsDir: uri,
@@ -308,6 +309,8 @@ func parseTSProject(ctx context.Context, repoPath string, opts lang.ParseOptions
308309

309310
cmd := exec.CommandContext(ctx, parserPath, args...)
310311
cmd.Env = append(os.Environ(), "NODE_OPTIONS=--max-old-space-size=65536")
312+
cmd.Env = append(cmd.Env, "ABCODER_TOOL_VERSION="+version.Version)
313+
cmd.Env = append(cmd.Env, "ABCODER_AST_VERSION="+uniast.Version)
311314
cmd.Stdout = os.Stdout
312315
cmd.Stderr = os.Stderr
313316

ts-parser/package-lock.json

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ts-parser/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "abcoder-ts-parser",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"description": "TypeScript AST parser for UNIAST v0.1.3 specification",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -43,4 +43,4 @@
4343
"ts-node": "^10.9.0",
4444
"typescript": "^5.0.0"
4545
}
46-
}
46+
}

ts-parser/src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const program = new Command();
1010
program
1111
.name('abcoder-ts-parser')
1212
.description('TypeScript AST parser for UNIAST v0.1.3 specification')
13-
.version('1.0.0');
13+
.version('0.0.4');
1414

1515
program
1616
.command('parse')
@@ -25,14 +25,14 @@ program
2525
.action(async (directory, options) => {
2626
try {
2727
const repoPath = path.resolve(directory);
28-
28+
2929
if (!fs.existsSync(repoPath)) {
3030
console.error(`Error: Directory ${repoPath} does not exist`);
3131
process.exit(1);
3232
}
3333

3434
console.log(`Parsing TypeScript repository: ${repoPath}`);
35-
35+
3636
const parser = new RepositoryParser(repoPath, options.tsconfig);
3737
const repository = await parser.parseRepository(repoPath, {
3838
loadExternalSymbols: false,
@@ -43,12 +43,12 @@ program
4343

4444
// Output the repository JSON file
4545
const outputPath = path.resolve(options.output);
46-
const jsonOutput = options.pretty
46+
const jsonOutput = options.pretty
4747
? JSON.stringify(repository, null, 2)
4848
: JSON.stringify(repository);
4949

5050
fs.writeFileSync(outputPath, jsonOutput);
51-
51+
5252
console.log(`Successfully parsed repository`);
5353
console.log(`Output written to: ${outputPath}`);
5454
console.log(`Total modules: ${Object.keys(repository.Modules).length}`);

ts-parser/src/types/uniast.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
* Root object representing an entire code repository.
1010
*/
1111
export interface Repository {
12-
/** UNIAST specification version. Fixed to "v0.1.3". */
13-
ASTVersion: string;
1412
/** Unique identifier for the repository. Field name in JSON is "id". */
1513
id: string;
14+
/** UNIAST specification version. Fixed to "v0.1.3". */
15+
ASTVersion: string;
16+
/** abcoder version used to parse the repository. Field name in JSON is "ToolVersion". */
17+
ToolVersion: string;
18+
/** File directory of the repository, usually should be an absolute path. */
19+
Path: string;
1620
/** Map of all modules in the repository. Keys are unique path identifiers. */
1721
Modules: Record<string, Module>;
1822
/**

0 commit comments

Comments
 (0)