Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions docs/uniast-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ A repository consists of entity Modules and relationship Graph

```json
{
"Identity": "/Users/bytedance/golang/work/abcoder/tmp/localsession",
"id": "/Users/bytedance/golang/work/abcoder/tmp/localsession",
"ASTVersion": "xx",
"ToolVersion": "yy",
"Path": "/a/b/localsession",
"Modules": {
"github.com/bytedance/gopkg@v0.0.0-20230728082804-614d0af6619b": {},
"github.com/cloudwego/localsession": {}
Expand All @@ -90,7 +93,7 @@ A repository consists of entity Modules and relationship Graph
}
```

- 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
- 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


- 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.
Expand All @@ -104,7 +107,10 @@ A repository consists of entity Modules and relationship Graph

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

- ASTVersion: The UniAST version used to parse
- ASTVersion: The UniAST version spefication when the repository is parsed

- ToolVersion: The abcoder version used to parse


### Module

Expand Down
11 changes: 8 additions & 3 deletions docs/uniast-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ Universal Abstract-Syntax-Tree 是 ABCoder 建立的一种 LLM 亲和、语言

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

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


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

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

- ASTVersion: 解析时使用的 UniAST 版本
- ASTVersion: 解析时对应的 UniAST 版本

- ToolVersion: 解析时使用的 abcoder 版本


### Module
Expand Down
2 changes: 2 additions & 0 deletions lang/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/cloudwego/abcoder/lang/register"
"github.com/cloudwego/abcoder/lang/rust"
"github.com/cloudwego/abcoder/lang/uniast"
"github.com/cloudwego/abcoder/version"
)

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

repo.ASTVersion = uniast.Version
repo.ToolVersion = version.Version

out, err := json.Marshal(repo)
if err != nil {
Expand Down
11 changes: 6 additions & 5 deletions lang/uniast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ type NodeGraph map[string]*Node

// Repository
type Repository struct {
ASTVersion string
Name string `json:"id"` // module name
Path string // repo path
Modules map[string]*Module // module name => module
Graph NodeGraph // node id => node
Name string `json:"id"` // module name
ASTVersion string // uniast version
ToolVersion string // abcoder version
Path string // repo absolute path
Modules map[string]*Module // module name => module
Graph NodeGraph // node id => node
}

func (r Repository) ID() string {
Expand Down
2 changes: 1 addition & 1 deletion lang/uniast/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

package uniast

const Version = "v0.1.3"
const Version = "v0.1.4"
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
"github.com/cloudwego/abcoder/llm/agent"
"github.com/cloudwego/abcoder/llm/mcp"
"github.com/cloudwego/abcoder/llm/tool"
"github.com/cloudwego/abcoder/version"
)

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

switch action {
case "version":
fmt.Fprintf(os.Stdout, "%s\n", Version)
fmt.Fprintf(os.Stdout, "%s\n", version.Version)

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

svr := mcp.NewServer(mcp.ServerOptions{
ServerName: "abcoder",
ServerVersion: Version,
ServerVersion: version.Version,
Verbose: *flagVerbose,
ASTReadToolsOptions: tool.ASTReadToolsOptions{
RepoASTsDir: uri,
Expand Down Expand Up @@ -308,6 +309,8 @@ func parseTSProject(ctx context.Context, repoPath string, opts lang.ParseOptions

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

Expand Down
9 changes: 6 additions & 3 deletions ts-parser/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ts-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "abcoder-ts-parser",
"version": "0.0.3",
"version": "0.0.4",
"description": "TypeScript AST parser for UNIAST v0.1.3 specification",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -43,4 +43,4 @@
"ts-node": "^10.9.0",
"typescript": "^5.0.0"
}
}
}
10 changes: 5 additions & 5 deletions ts-parser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const program = new Command();
program
.name('abcoder-ts-parser')
.description('TypeScript AST parser for UNIAST v0.1.3 specification')
.version('1.0.0');
.version('0.0.4');

program
.command('parse')
Expand All @@ -25,14 +25,14 @@ program
.action(async (directory, options) => {
try {
const repoPath = path.resolve(directory);

if (!fs.existsSync(repoPath)) {
console.error(`Error: Directory ${repoPath} does not exist`);
process.exit(1);
}

console.log(`Parsing TypeScript repository: ${repoPath}`);

const parser = new RepositoryParser(repoPath, options.tsconfig);
const repository = await parser.parseRepository(repoPath, {
loadExternalSymbols: false,
Expand All @@ -43,12 +43,12 @@ program

// Output the repository JSON file
const outputPath = path.resolve(options.output);
const jsonOutput = options.pretty
const jsonOutput = options.pretty
? JSON.stringify(repository, null, 2)
: JSON.stringify(repository);

fs.writeFileSync(outputPath, jsonOutput);

console.log(`Successfully parsed repository`);
console.log(`Output written to: ${outputPath}`);
console.log(`Total modules: ${Object.keys(repository.Modules).length}`);
Expand Down
8 changes: 6 additions & 2 deletions ts-parser/src/types/uniast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
* Root object representing an entire code repository.
*/
export interface Repository {
/** UNIAST specification version. Fixed to "v0.1.3". */
ASTVersion: string;
/** Unique identifier for the repository. Field name in JSON is "id". */
id: string;
/** UNIAST specification version. Fixed to "v0.1.3". */
ASTVersion: string;
/** abcoder version used to parse the repository. Field name in JSON is "ToolVersion". */
ToolVersion: string;
/** File directory of the repository, usually should be an absolute path. */
Path: string;
/** Map of all modules in the repository. Keys are unique path identifiers. */
Modules: Record<string, Module>;
/**
Expand Down
13 changes: 10 additions & 3 deletions ts-parser/src/utils/package-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export class ProjectFactory {
* Handles tsconfig.json resolution and project references
*/
static createProjectForSingleRepo(
projectRoot: string,
projectRoot: string,
tsConfigPath?: string,
tsConfigCache?: TsConfigCache
): Project {
Expand Down Expand Up @@ -492,7 +492,7 @@ export class ProjectFactory {
return false;
}
});

if (existingFiles.length > 0) {
try {
project.addSourceFilesAtPaths(existingFiles);
Expand Down Expand Up @@ -523,7 +523,8 @@ export class ProjectFactory {
* Repository Factory - Centralized creation of Repository objects
*/
export class RepositoryFactory {
private static readonly AST_VERSION = 'v0.1.3';
private static AST_VERSION = process.env.ABCODER_AST_VERSION || 'unknown';
private static TOOL_VERSION = process.env.ABCODER_TOOL_VERSION || 'unknown';

/**
* Create a repository for a single project/repository
Expand All @@ -532,7 +533,9 @@ export class RepositoryFactory {
const absolutePath = path.resolve(repoPath);
return {
ASTVersion: RepositoryFactory.AST_VERSION,
ToolVersion: RepositoryFactory.TOOL_VERSION,
id: path.basename(absolutePath),
Path: absolutePath,
Modules: {},
Graph: {},
};
Expand All @@ -544,6 +547,8 @@ export class RepositoryFactory {
static createPackageRepository(pkg: MonorepoPackage, module: Module): Repository {
return {
ASTVersion: RepositoryFactory.AST_VERSION,
ToolVersion: RepositoryFactory.TOOL_VERSION,
Path: pkg.absolutePath,
id: pkg.name || path.basename(pkg.absolutePath),
Modules: { [module.Name]: module },
Graph: {},
Expand All @@ -556,6 +561,8 @@ export class RepositoryFactory {
static createEmptyRepository(id: string): Repository {
return {
ASTVersion: RepositoryFactory.AST_VERSION,
ToolVersion: RepositoryFactory.TOOL_VERSION,
Path: '',
id,
Modules: {},
Graph: {},
Expand Down
29 changes: 26 additions & 3 deletions version.go → version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,31 @@
* limitations under the License.
*/

package main
package version

const (
Version = "0.2.1"
import (
"debug/buildinfo"
"fmt"
"os"
)

var Version = "unknown"

func init() {
path, err := os.Executable()
if err != nil {
fmt.Fprintf(os.Stderr, "fail to get executable path: %v\n", err)
return
}
data, err := os.Open(path)
if err != nil {
fmt.Fprintf(os.Stderr, "fail to read executable file: %v\n", err)
return
}
info, err := buildinfo.Read(data)
Comment thread
FGYFFFF marked this conversation as resolved.
if err != nil {
fmt.Fprintf(os.Stderr, "fail to read build info: %v\n", err)
return
}
Version = info.Main.Version
}
Loading