ข้ามไปยังเนื้อหา

เริ่มต้นใช้งาน

เริ่มต้นใช้งาน codeknit ภายใน 5 นาที

คุณจะต้องมี:

  • Go 1.26+
  • C compiler (CGo จำเป็นสำหรับ tree-sitter)
Terminal window
git clone https://github.com/awslabs/codeknit.git
cd codeknit
make build
# Binary is at ./bin/codeknit

เพิ่มไบนารีลงใน PATH ของ shell ของคุณ:

Terminal window
# bash (~/.bashrc)
export PATH="$PATH:$(pwd)/bin"
# zsh (~/.zshrc)
export PATH="$PATH:$(pwd)/bin"
# fish (~/.config/fish/config.fish)
fish_add_path $(pwd)/bin

รีโหลด shell ของคุณหรือรัน source ~/.bashrc (หรือ ~/.zshrc) เพื่อให้การเปลี่ยนแปลงมีผล

ตรวจสอบว่า codeknit ทำงานได้:

Terminal window
codeknit --version

รันการแปลงครั้งแรกบน codebase:

Terminal window
codeknit parse ./myproject

คำสั่งนี้:

  • แปลงไฟล์ต้นฉบับทั้งหมดใน ./myproject
  • ดึงข้อมูลโครงสร้าง (ฟังก์ชัน คลาส ความสัมพันธ์)
  • เขียนไฟล์ .skt ที่แบ่งเป็นชิ้นไปยัง ./skeleton/ (ไดเรกทอรีเอาต์พุตเริ่มต้น)

หากคุณรันคำสั่งนี้อีกครั้ง ให้ใช้ --clean เพื่อลบเอาต์พุตก่อนหน้า:

Terminal window
codeknit parse ./myproject --clean

ไฟล์ .skt มีข้อมูลโค้ดที่มีโครงสร้าง นี่คือตัวอย่างเล็กน้อย:

[symbols]
## src/main.go
S1 module/package L1-L1 main {}
S2 type/struct L5-L8 Server {exported}
S3 callable/function L10-L12 NewServer(addr: string) -> *S2 {exported}
S4 callable/method L14-L19 Start() {receiver=*Server}
[edges]
S2 --contains--> S4
S3 --returns--> S2

ส่วนสำคัญ:

  • [symbols]: นิยามที่จัดกลุ่มตามไฟล์ แสดงชื่อ ช่วงบรรทัด และข้อมูลเมตา
  • [edges]: ความสัมพันธ์ เช่น contains, calls, inherits หรือ returns

เมื่อคุณได้รันการแปลงครั้งแรกแล้ว: