@haydenull/code-canvas 1.1.0 → 1.2.0
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 +13 -67
- package/dist/cli.js +18 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,85 +4,31 @@ Code Canvas 将代码的控制流和调用关系转换为可交互的流程图
|
|
|
4
4
|
|
|
5
5
|
项目包含:
|
|
6
6
|
|
|
7
|
-
- `@haydenull/code-canvas
|
|
8
|
-
- `code-canvas-generator` Skill
|
|
7
|
+
- `@haydenull/code-canvas`:校验 `.logic.json` 产物,并在 Web Viewer 中展示节点、分支、调用关系、模块分组和源码片段。
|
|
8
|
+
- `code-canvas-generator` Skill:让支持 Agent Skill 的编码助手阅读真实源码,并生成可被 Code Canvas 展示的流程图产物。
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## 安装 CLI
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
- 本地开发:[Bun](https://bun.sh/)。
|
|
14
|
-
|
|
15
|
-
## 快速开始
|
|
16
|
-
|
|
17
|
-
安装依赖:
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
bun install
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
打开仓库内的示例流程图:
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
bun run view
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
命令会启动本地服务并输出访问地址。默认监听 `127.0.0.1`,端口由系统自动分配。
|
|
30
|
-
|
|
31
|
-
## CLI 用法
|
|
32
|
-
|
|
33
|
-
无需安装即可通过 `npx` 执行已发布的 CLI:
|
|
12
|
+
推荐本地全局安装 CLI:
|
|
34
13
|
|
|
35
14
|
```bash
|
|
36
|
-
|
|
37
|
-
npx @haydenull/code-canvas view artifacts/example.logic.json
|
|
38
|
-
npx @haydenull/code-canvas artifact path
|
|
15
|
+
npm install -g @haydenull/code-canvas@latest
|
|
39
16
|
```
|
|
40
17
|
|
|
41
|
-
|
|
18
|
+
## 安装 Skill
|
|
42
19
|
|
|
43
|
-
|
|
44
|
-
bun src/cli.ts validate artifacts/example.logic.json
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
启动 Viewer 前需要先构建静态资源。`view` 支持指定监听地址和端口:
|
|
48
|
-
|
|
49
|
-
```bash
|
|
50
|
-
bun run build
|
|
51
|
-
node dist/cli.js view artifacts/example.logic.json --host 0.0.0.0 --port 4173
|
|
52
|
-
```
|
|
20
|
+
`code-canvas-generator` Skill 位于仓库的 [`skills/code-canvas-generator`](skills/code-canvas-generator/SKILL.md) 目录。
|
|
53
21
|
|
|
54
|
-
|
|
22
|
+
可以使用 `npx skills` 安装:
|
|
55
23
|
|
|
56
24
|
```bash
|
|
57
|
-
|
|
58
|
-
node dist/cli.js validate artifacts/example.logic.json
|
|
59
|
-
node dist/cli.js view artifacts/example.logic.json
|
|
25
|
+
npx skills add haydenull/code-canvas --skill code-canvas-generator
|
|
60
26
|
```
|
|
61
27
|
|
|
62
|
-
|
|
28
|
+
也可以使用 [haydenull/skills-manager](https://github.com/haydenull/skills-manager) 安装。
|
|
63
29
|
|
|
64
|
-
仓库内置的 [`code-canvas-generator`](skills/code-canvas-generator/SKILL.md) Skill 会读取指定代码入口及必要的调用链,调用 CLI 获取系统临时目录下的 `.logic.json` 输出路径,并将生成的流程图产物写入该路径。
|
|
65
30
|
|
|
66
|
-
##
|
|
31
|
+
## 文档
|
|
67
32
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
bun run check # TypeScript 类型检查
|
|
71
|
-
bun run build # 构建 CLI 并执行类型检查
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
发布 npm 包见 [发布文档](docs/publishing.md)。
|
|
75
|
-
|
|
76
|
-
## 项目结构
|
|
77
|
-
|
|
78
|
-
```text
|
|
79
|
-
src/
|
|
80
|
-
├── cli.ts # CLI 入口和本地 Viewer 服务
|
|
81
|
-
├── shared/
|
|
82
|
-
│ ├── flow.ts # Artifact 到 React Flow 数据的转换与布局
|
|
83
|
-
│ └── schema.ts # Artifact 数据结构与校验
|
|
84
|
-
└── viewer/ # React 可视化界面
|
|
85
|
-
skills/
|
|
86
|
-
└── code-canvas-generator # Code Canvas 产物生成 Skill
|
|
87
|
-
artifacts/ # 生成的流程图产物和示例
|
|
88
|
-
```
|
|
33
|
+
- [开发说明](docs/development.md)
|
|
34
|
+
- [发布 npm 包](docs/publishing.md)
|
package/dist/cli.js
CHANGED
|
@@ -217,6 +217,11 @@ var viewerContentTypes = {
|
|
|
217
217
|
".js": "text/javascript; charset=utf-8",
|
|
218
218
|
".svg": "image/svg+xml"
|
|
219
219
|
};
|
|
220
|
+
function loadVersion() {
|
|
221
|
+
const packagePath = fileURLToPath(new URL("../package.json", import.meta.url));
|
|
222
|
+
const packageJson = JSON.parse(readFileSync(packagePath, "utf8"));
|
|
223
|
+
return packageJson.version;
|
|
224
|
+
}
|
|
220
225
|
function loadArtifact(path) {
|
|
221
226
|
if (!existsSync3(path)) {
|
|
222
227
|
throw new Error(`Artifact not found: ${path}`);
|
|
@@ -299,16 +304,26 @@ async function view(artifactPath, { host, port }) {
|
|
|
299
304
|
resolveListen();
|
|
300
305
|
});
|
|
301
306
|
});
|
|
307
|
+
const stop = () => {
|
|
308
|
+
console.log(`
|
|
309
|
+
Stopping viewer...`);
|
|
310
|
+
server.close(() => {
|
|
311
|
+
process.off("SIGINT", stop);
|
|
312
|
+
process.off("SIGTERM", stop);
|
|
313
|
+
});
|
|
314
|
+
};
|
|
315
|
+
process.once("SIGINT", stop);
|
|
316
|
+
process.once("SIGTERM", stop);
|
|
302
317
|
const address = server.address();
|
|
303
318
|
const listeningPort = typeof address === "object" && address ? address.port : port;
|
|
304
319
|
console.log(`Local: http://${host}:${listeningPort}/`);
|
|
305
320
|
console.log(`Serving artifact: ${artifactPath}`);
|
|
306
321
|
}
|
|
307
322
|
var program = new Command;
|
|
308
|
-
program.name("code-canvas");
|
|
309
|
-
program.command("validate <artifactPath>").action(validate);
|
|
323
|
+
program.name("code-canvas").description("validate and visualize Code Canvas .logic.json artifacts").version(loadVersion(), "-v, --version", "display version number");
|
|
324
|
+
program.command("validate <artifactPath>").description("validate a .logic.json artifact").action(validate);
|
|
310
325
|
program.command("artifact").description("manage logic artifact files").command("path").description("print a new temporary .logic.json path").action(printArtifactPath);
|
|
311
|
-
program.command("view <artifactPath>").option("--host <host>", "host", "127.0.0.1").option("--port <port>", "port", parsePort, 0).action(view);
|
|
326
|
+
program.command("view <artifactPath>").description("serve a .logic.json artifact in the local viewer").option("--host <host>", "host", "127.0.0.1").option("--port <port>", "port", parsePort, 0).action(view);
|
|
312
327
|
program.parseAsync().catch((error) => {
|
|
313
328
|
console.error(error instanceof Error ? error.message : error);
|
|
314
329
|
process.exit(1);
|