@openqa-cn/codexqa 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +142 -0
- package/bin/codexqa.js +37 -0
- package/package.json +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# @openqa-cn/codexqa
|
|
2
|
+
|
|
3
|
+
把本地或远程代码仓库解析成可查询的符号图:查函数怎么实现、谁在调用它、改一处会影响谁,也能搜报错、看架构 Wiki、用自然语言问仓库,或打开网页界面浏览。
|
|
4
|
+
|
|
5
|
+
需要 **Node.js >= 18**。当前已发布 **macOS Apple Silicon** 安装包。
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @openqa-cn/codexqa --registry https://registry.npmjs.org/
|
|
9
|
+
codexqa --help
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
命令找不到时,把 npm 全局 bin 加进 PATH:`export PATH="$(npm prefix -g)/bin:$PATH"`。Windows 常见位置是 `%AppData%\npm`。
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 能做什么
|
|
17
|
+
|
|
18
|
+
| 你想做的事 | 用什么 |
|
|
19
|
+
|---|---|
|
|
20
|
+
| 给仓库建索引 | `codexqa index` |
|
|
21
|
+
| 看仓库有多大、什么语言 | `codexqa stats` / `query summary` |
|
|
22
|
+
| 某个函数怎么实现、谁调用它 | `query symbols` → `source` / `edges` |
|
|
23
|
+
| 改这里会影响谁 | `query reach` |
|
|
24
|
+
| 两个符号有没有关系 | `query path` |
|
|
25
|
+
| 搜报错、注释、字符串 | `search-index` 之后 `query search` |
|
|
26
|
+
| 用自然语言问仓库 | `codexqa chat`(需配置 LLM) |
|
|
27
|
+
| 看架构说明 | `wiki` + `wiki embed` 之后 `query wiki` |
|
|
28
|
+
| 打开网页界面 | `codexqa serve --open` |
|
|
29
|
+
|
|
30
|
+
数据在本机 `~/.codexqa/`。卸载 CLI 不会删索引和会话:`npm uninstall -g @openqa-cn/codexqa` 或 `codexqa uninstall`。
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 快速开始
|
|
35
|
+
|
|
36
|
+
先给仓库建索引(本地目录或 git URL):
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
codexqa index /path/to/repo
|
|
40
|
+
codexqa index https://github.com/org/repo.git
|
|
41
|
+
codexqa index https://github.com/org/repo.git -b main
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
默认增量更新;`--full` 强制全量。看已索引的仓库:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
codexqa repos
|
|
48
|
+
codexqa stats /path/to/repo
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`codexqa repos` 里的 `repo_id`(如 `github.com/org/repo@main`)可以原样传给后面的命令。本地路径、统一标识、都可以。
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 查符号和调用关系
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# 按名字 / 前缀 / 文件路径找符号
|
|
59
|
+
codexqa query --repo /path/to/repo symbols --name parse_file
|
|
60
|
+
codexqa query --repo /path/to/repo symbols --name-prefix Repo
|
|
61
|
+
codexqa query --repo /path/to/repo symbols --file-contains db/src
|
|
62
|
+
|
|
63
|
+
# 看实现、调用它的人、它调用了谁
|
|
64
|
+
codexqa query --repo /path/to/repo source --id <uuid>
|
|
65
|
+
codexqa query --repo /path/to/repo edges --id <uuid> --direction in
|
|
66
|
+
codexqa query --repo /path/to/repo edges --id <uuid> --direction out
|
|
67
|
+
|
|
68
|
+
# 影响面(默认向内);追调用链请显式 --direction out
|
|
69
|
+
codexqa query --repo /path/to/repo reach --id <uuid> --direction in
|
|
70
|
+
codexqa query --repo /path/to/repo reach --id <uuid> --direction out --depth 2
|
|
71
|
+
|
|
72
|
+
# 两个符号之间有没有路径
|
|
73
|
+
codexqa query --repo /path/to/repo path --from <uuid> --to <uuid>
|
|
74
|
+
|
|
75
|
+
# 仓库概览、看某个节点
|
|
76
|
+
codexqa query --repo /path/to/repo summary
|
|
77
|
+
codexqa inspect <node-id> --repo /path/to/repo
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`query` 输出 JSON,方便脚本接着处理。人读可以用 `repos` / `stats` / `inspect`。
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## 全文检索
|
|
85
|
+
|
|
86
|
+
索引之后再跑一次即可,之后 `index` 会自动维护:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
codexqa search-index /path/to/repo
|
|
90
|
+
codexqa query --repo /path/to/repo search --query "verify_jwt"
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
适合搜报错文案、中文注释、字符串。没有全文索引时,先用 `symbols` 或 `files`。
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## 对话和网页
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# 终端里问仓库(交互,或 -m 问一句就退出)
|
|
101
|
+
codexqa chat /path/to/repo
|
|
102
|
+
codexqa chat /path/to/repo -m "支付重试逻辑在哪?"
|
|
103
|
+
codexqa chat /path/to/repo --session <id>
|
|
104
|
+
|
|
105
|
+
# 浏览器里看文件、符号图、Wiki,以及同一套对话
|
|
106
|
+
codexqa serve --open
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`chat` 和网页共用会话,可以互相续上。对话和 Wiki 需要在 `~/.codexqa/config.toml` 里配置 LLM(只做索引和查询不用配):
|
|
110
|
+
|
|
111
|
+
```toml
|
|
112
|
+
[llm]
|
|
113
|
+
base_url = "https://api.openai.com/v1"
|
|
114
|
+
api_key = "sk-..."
|
|
115
|
+
model = "gpt-4o-mini"
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
改完配置后执行 `codexqa restart`。
|
|
119
|
+
|
|
120
|
+
架构 Wiki(可选,会调用 LLM):
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
codexqa wiki /path/to/repo
|
|
124
|
+
codexqa wiki embed /path/to/repo
|
|
125
|
+
codexqa query --repo /path/to/repo wiki --query "重试逻辑在哪里处理"
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Wiki 重新生成后必须再跑一次 `wiki embed`。Wiki 是路由提示,以源码为准。
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## 常用维护
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
codexqa status # daemon 是否在跑
|
|
136
|
+
codexqa stop
|
|
137
|
+
codexqa restart # 改完配置后要重启才生效
|
|
138
|
+
codexqa delete /path/to/repo
|
|
139
|
+
codexqa session list
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
完整子命令见 `codexqa --help` 和 `codexqa query --help`。
|
package/bin/codexqa.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// src/index.ts
|
|
3
|
+
var { spawn } = require("node:child_process");
|
|
4
|
+
var { argv, stderr, exit, platform, arch } = require("node:process");
|
|
5
|
+
var PLATFORM_MAP = {
|
|
6
|
+
darwin: { arm64: "darwin-arm64", x64: "darwin-x64" },
|
|
7
|
+
linux: { arm64: "linux-arm64", x64: "linux-x64" },
|
|
8
|
+
win32: { x64: "win32-x64" }
|
|
9
|
+
};
|
|
10
|
+
function fail(msg) {
|
|
11
|
+
stderr.write(msg);
|
|
12
|
+
exit(1);
|
|
13
|
+
throw new Error("unreachable");
|
|
14
|
+
}
|
|
15
|
+
function resolveBinary() {
|
|
16
|
+
const suffix = PLATFORM_MAP[platform]?.[arch];
|
|
17
|
+
if (!suffix) {
|
|
18
|
+
fail(`codexqa: unsupported platform ${platform}-${arch}
|
|
19
|
+
`);
|
|
20
|
+
}
|
|
21
|
+
const pkg = `@openqa-cn/codexqa-${suffix}`;
|
|
22
|
+
const binName = platform === "win32" ? "bin/codexqa.exe" : "bin/codexqa";
|
|
23
|
+
try {
|
|
24
|
+
return require.resolve(`${pkg}/${binName}`);
|
|
25
|
+
} catch {
|
|
26
|
+
fail(`codexqa: platform package ${pkg} not installed.
|
|
27
|
+
` + ` try: npm install -g @openqa-cn/codexqa
|
|
28
|
+
`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
var child = spawn(resolveBinary(), argv.slice(2), { stdio: "inherit" });
|
|
32
|
+
child.on("exit", (code) => exit(code ?? 1));
|
|
33
|
+
child.on("error", (err) => {
|
|
34
|
+
stderr.write(`codexqa: failed to launch binary: ${err.message}
|
|
35
|
+
`);
|
|
36
|
+
exit(1);
|
|
37
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openqa-cn/codexqa",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "把代码仓库解析成可查询的符号图:查实现、追调用、搜报错、看架构,也能对话或打开网页界面。",
|
|
5
|
+
"bin": {
|
|
6
|
+
"codexqa": "bin/codexqa.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"bin"
|
|
10
|
+
],
|
|
11
|
+
"optionalDependencies": {
|
|
12
|
+
"@openqa-cn/codexqa-darwin-arm64": "0.1.3",
|
|
13
|
+
"@openqa-cn/codexqa-darwin-x64": "0.1.3",
|
|
14
|
+
"@openqa-cn/codexqa-linux-x64": "0.1.3",
|
|
15
|
+
"@openqa-cn/codexqa-win32-x64": "0.1.3"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "bun build src/index.ts --format=cjs --target=node --outfile bin/codexqa.js && node -e \"const fs=require('fs');const p='bin/codexqa.js';const s=fs.readFileSync(p,'utf8');const out=s.replace(/^(#!.*\\n)+/,'');fs.writeFileSync(p,'#!/usr/bin/env node\\n'+out)\"",
|
|
19
|
+
"prepublishOnly": "bun run build",
|
|
20
|
+
"dev": "bun run src/index.ts",
|
|
21
|
+
"test": "bun test"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "^6.0",
|
|
25
|
+
"@types/bun": "latest",
|
|
26
|
+
"@types/node": "^22"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=18"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
}
|
|
34
|
+
}
|